jtextfield

Detecting JTextField “deselect” event

大城市里の小女人 提交于 2020-02-09 04:41:41
问题 Is there some way to detect if a JTextField is deselected, i.e. the field WAS selected but now you have selected something else. The reason why I want to do this is because I want to check my users forms for any illegal characters before they try to submit their data. If there is some easier way to do that, instead of the way I'm trying to solve it, I'll gladly accept enlightenment. 回答1: At first though use a FocusAdapter and override focusLost(FocusEvent fe) which will be called when

Clearing JTextfields to write multiple data to txt file

北城余情 提交于 2020-02-02 14:06:42
问题 excuse the probably simple question (and the terrible layout methods). The code I have successfully writes inputted data to a txt file and on clicking "submit" closes the input window, leaving the "menu" open, with options to add a user (this code) or search properties (unrelated). I can enter one set of details to the txt file with no problem, but when reopening the AddUser window, no matter what is typed in to the boxes the same data is inputted into the file as the previous time, unless

Java have a int value using setText

橙三吉。 提交于 2020-01-30 11:47:48
问题 I'm trying to set an int value using jTextField and the setText method. But of course setText wants a String. How do I get round this? I'll give you a snippet of the code: private void setAllTextFields(FilmSystem e){ getFilmNameTF().setText(e.getFilmName()); lectureTF.setText(e.getLecture()); ageTF.setText(e.getAge()); priceTF.setText(e.getTicketCost()); seatsTF.setText(e.getNoOfSeats()); seatsTF is a jTextField and getNoOfSeats is a method in another class that returns a int value. Thanks

After updating JComboBox, how to refresh length of box

人盡茶涼 提交于 2020-01-25 20:09:21
问题 I am trying to create a way to update a JComboBox so that when the user enters something into the text field, some code will process the entry and update the JComboBox accordingly.The one issue that I am having is I can update the JComboBox, but the first time it is opened, the box has not refresh the length of the options in it and as seen in the code below it displays extra white space. I do not know if there is a better different way to do this, but this is what I came up with. Thanks for

Append value to JTextField?

我的梦境 提交于 2020-01-25 14:27:31
问题 I want to append a value into a JTextField in Java. Something like: String btn1="1"; textField.appendText(btn1); 回答1: I think you'll find setText is the answer. Just combine the current value with the new value: textField.setText(textField.getText() + newStringHere); 回答2: If you text field is not editable, you could use: textField.replaceSelection("..."); If it is editable you might use: textField.setCaretPosition( textField.getDocument().getLength() ); textField.replaceSelection("..."); This

Append value to JTextField?

情到浓时终转凉″ 提交于 2020-01-25 14:27:09
问题 I want to append a value into a JTextField in Java. Something like: String btn1="1"; textField.appendText(btn1); 回答1: I think you'll find setText is the answer. Just combine the current value with the new value: textField.setText(textField.getText() + newStringHere); 回答2: If you text field is not editable, you could use: textField.replaceSelection("..."); If it is editable you might use: textField.setCaretPosition( textField.getDocument().getLength() ); textField.replaceSelection("..."); This

JTextField crops text when using custom TrueType font. How to make it display text normally?

馋奶兔 提交于 2020-01-25 03:36:08
问题 So, the problem is definitely with the font. Question is how to make the text field display text fully. Example: import javax.swing.*; import java.awt.*; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; class Example extends JFrame{ public Example(){ setLayout(new BorderLayout()); Font myFont = null; try { URL link = new URL("http://rghost.ru/download/50564305

Set DocumentFilter on JOptionPane

為{幸葍}努か 提交于 2020-01-24 13:05:07
问题 I'm using: String s = JOptionPane.showInputDialog(...); to get a response back from the user to a question; the dialog is set up to display a text field for the response. I'd like to limit the characters allowed in the response to alphanumeric and '_' only. Is it possible to install a DocumentFilter on the text field without implementing my own custom dialog from scratch? 回答1: Access the autocreated text field of JOptionPane is theoretically possible, but it's IMHO wrong way. Here is the

JTextField, using Document Filter to filter integers and periods

江枫思渺然 提交于 2020-01-24 05:10:06
问题 EDIT - added at then end of the post the answer we were able to achieve This is my first post in SO, so i hope i can ask everything right! I searched and didn't quite find a answer to my question despite similar questions being posted, so i hope this isn't a repost. This is what a i got, a small application that uses JTextField to receive user's input and on top of that i have a DocumentFilter so the user can only input integers and a period in order to receive values that represent weight.

How do I record the highest value in a variable [closed]

北慕城南 提交于 2020-01-24 02:12:20
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . I have a variable and I need to find the highest value that was there. That value constantly changes. I need to put that highest value in a textfield. //This is full program. Posting the code won't help. I will try to explain the program: It's Heads or Tails. You press two buttons, heads and tails.