jtextfield

How to get string from JTextField and save it in variable?

泄露秘密 提交于 2021-02-11 10:39:29
问题 I am making a simple kid game that will ask the user to enter his/her name in a JTextField and that name will shown in other class after ending the game. I made new object and used it to call the method getName but when I call the method it return null I want it to return the name that the user entered. This is the code: package learn_englishTest; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt

Save only if multiple JTextFields are not empty

与世无争的帅哥 提交于 2021-02-11 07:21:07
问题 I have multiple JTextField s and JComboBox in my JFrame . So whenever I click the _Add_ button it will check if the four (4) text fields in Current Medication Panel is Empty. If it is not then Execute, but it also depends if the Personal info Panel text fields are filled. But I have a problem when I use the if and else statement, if I use the if and else : if(condition if the first textfield is empty) { // execute something like the textfield turn to red } else if(condition if the second

Setting the height of a JTextFrame

陌路散爱 提交于 2021-02-08 10:20:59
问题 The following class creates a form (Jpanel) tasked with acquiring multiples Strings from the user and do something with them. It it functionally working, but it bugs me that the height of the JTextField s (a component that allows for the modification of one line of text) is automatically adjusted and can became extravagantly big. I have tried the method setBounds() , but: I do not want to calculate the position or width of the JTextField , just its height; and It does not limit the height of

automatic update jtextfield

最后都变了- 提交于 2021-02-05 11:37:55
问题 Does anyone know how to update a jTextfield every 5 secondes? Automatic. So no userinput is required. It is used to update time in a textfield. This is what i tried but then my program freezes. while(true){ Thread.sleep(1000); txtCheck.setText(convert.getCheck()); System.out.println("Ja"); } convert is a thread, i tried to throw an exception but failed, cause Eclise says Threads can't throw exceptions. Convert.getCheck: public String getCheck() { return check; } 回答1: You want to use a Swing

Limit the amount of characters typed into a JTextField [duplicate]

别等时光非礼了梦想. 提交于 2021-01-28 15:26:36
问题 This question already has answers here : Limiting TextField inputs (2 answers) Closed 6 years ago . I figured this would be a simple search on the web but I can't figure this out. Here is what I'm working with so far. Ignore the eventHandler, I know its empty. I want to limit the charField JTextField so that the user can only type one character. I figured this would be easy because of all the apps that limit the amount of numbers you can type when entering State or Zipcode. To be clear, I'm

DocumentFilter for negative and positive integer

守給你的承諾、 提交于 2021-01-28 08:21:07
问题 I know this is a common question, but I'm trying to create a TextField that only accept int numbers, and it's almost done, here's the code: Create textfield: nome = new JFormattedTextField(); nome.setHorizontalAlignment(SwingConstants.CENTER); nome.setColumns(2); DocumentFilter filtro = new FiltroNumero(); ((AbstractDocument) nome.getDocument()).setDocumentFilter(filtro); panel.add(nome); DocummentFilter: public class FiltroNumero extends DocumentFilter{ public void insertString

Hide/Show JTextField

Deadly 提交于 2020-02-29 07:32:25
问题 I have a JTextField that in the begin it have to be hidden and in a specific situation it have to show. This is my code: package StudentNotes; import java.awt.BorderLayout; public class EditCourse extends JDialog { private JTextField textField; /** * Create the dialog. */ public EditCourse(JDialog mainFrame, final StudApp studAppObj) { super(mainFrame, ModalityType.APPLICATION_MODAL); setPreferredSize(new Dimension(330, 200)); setTitle("Edit course"); setDefaultCloseOperation(JDialog.DISPOSE

Hide/Show JTextField

半城伤御伤魂 提交于 2020-02-29 07:31:06
问题 I have a JTextField that in the begin it have to be hidden and in a specific situation it have to show. This is my code: package StudentNotes; import java.awt.BorderLayout; public class EditCourse extends JDialog { private JTextField textField; /** * Create the dialog. */ public EditCourse(JDialog mainFrame, final StudApp studAppObj) { super(mainFrame, ModalityType.APPLICATION_MODAL); setPreferredSize(new Dimension(330, 200)); setTitle("Edit course"); setDefaultCloseOperation(JDialog.DISPOSE

Customize JTextField in Java Swings - add simple/compound/custom borders to JTextField

馋奶兔 提交于 2020-02-25 07:18:27
问题 I have a Netbeans java project with a lot of forms. There are many JTextField s in those forms. I would like to customize those text fields with a custom border. private void tfUserNameFocusGained(java.awt.event.FocusEvent evt) { tfUserName.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 255)), javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153,