jtextfield

Creating arrays of swing components or specifically JTextFields and giving each of them different properties in java

試著忘記壹切 提交于 2019-12-25 18:48:11
问题 So I'm trying to create a large number of JTextField s and use them as nodes in a binary tree program I'm trying to make. Is there a way to create an array of JTextFields, something like: JTextField nodes[]=new JTextField[30]; If so, how do I define or give every one of them different properties or the property I want them to have? Thanks! 回答1: JTextField[] fields = new JTextField[30]; for(int i = 0; i<fields.length; i++){ fields = new JTextField(); } //then you can access them and modify

Using JTextField for user input

拜拜、爱过 提交于 2019-12-25 17:04:51
问题 Thanks for your help guys...now the program works and runs like it should.. but I have 2 more question. 1.How can I get the output into a JTestField t4 or t5 2.How can I close the application using the JButton Buton3 import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.JButton; import javax.swing.JFrame; public class TriangleFarfan{ JFrame Triangle = new JFrame("Triangle Calculator"); JButton Button1 =

Maximum length of JTextField and only accepts numbers?

孤街醉人 提交于 2019-12-25 16:50:55
问题 I want the user to input a maximum of 8 numbers as it is a field for Mobile number. This is my JTextField. txtMobile = new JTextField(); txtMobile.setColumns(10); txtMobile.setBounds(235, 345, 145, 25); add(txtMobile); While we're at it, how do I check for invalid characters like >> '^%$* in a JTextField ? 1)Maximum Length 2)Accepts only numbers 3)Check for invalid characters 4)Check if it's a valid email address Please help :D 回答1: You could use a JFormattedField , check out How to Use

How to update JTextfield after click SAVE button

若如初见. 提交于 2019-12-25 07:50:00
问题 I have a main frame : JFrame>contentFrame>ScrollPane>BigPanel>panel_1T private JPanel contentPane; private JPanel BigPanel; private JPanel panel_1T; In panel_1T, I have put a FOOD button WITH its actionListener: JButton button_19 = new JButton("FOOD"); button_19.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { newFoodUI nf = new newFoodUI();//Open other class nf.setVisible(true); nf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); } }); panel

array TextField

流过昼夜 提交于 2019-12-25 05:29:08
问题 Na is a parameter. I'm sure that this parameter is correct. I've declared an array of Na JTextField, And I would like to use one of them. But when I run my code, There is an exception... That's my code : import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; class Panneau_fenetre1A extends JPanel { public Panneau_fenetre1A(int Na) { JTextField[] allField = new JTextField [Na]; for(int i = 0;i<Na;i++) { allField[i].setText(String.valueOf(0)); allField[i].setBounds

reading ArrayList JTextFields

随声附和 提交于 2019-12-25 04:57:52
问题 My program starts by prompting the user how many text fields they would like to have public class textEvent1 implements ActionListener { //action listener for "how many masses?" public void actionPerformed (ActionEvent e) { n = (int)(Double.parseDouble(massNumField.getText())); next I create a for loop to create labels and textfields (which I have created lists for because I dont know how many there will be). There are a couple of lists but I will give an example of just one. ArrayList masses

Interacting with multiple textfields with KeyListener for Java

帅比萌擦擦* 提交于 2019-12-25 03:47:06
问题 I'm making a small java program where I have two JTextFields labeled field1, field2. I have a calculate button as well which initially set to disabled. I want the button only to be enabled when the 2 text boxes have values in them. Currently what i have for the key listener is: field1.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { if (field1.getDocument().getLength() > 0) { bt1.setEnabled(true); } else { bt1.setEnabled(false); } } });

Accessing GUI JTextField objects that are dynamically generated

旧时模样 提交于 2019-12-25 03:32:42
问题 I am writing a program that contains a JButton . Every time the button is clicked, a new JTextField is added to a JPanel . My problem is that, after the user has created all the JTextFields and filled them with information, I need to get the text of each field. How can I get access to the JTextFields when they are dynamically generated, as they don't have instance names? Is there a better way to get the text of each one, without knowing their instance name. Here is the code of the

JTextField's real time formatting of user input

心不动则不痛 提交于 2019-12-25 02:52:02
问题 I would like to format the user input in real time, while they are typing. For example, if I want the user to enter a date, I would like the text field to show in light gray the date format. The user would only be able to enter valid digits while he is typing. If I need the user to enter a phone number, the format would be displayed in light gray in the text field and the user would only be able to enter valid digits... A javascript example of this can be found here: http://omarshammas.github

java text in textfield messing up

爱⌒轻易说出口 提交于 2019-12-25 02:38:26
问题 [UPDATE] i fixed the problem. user "Hovercraft Full Of Eels" was right, i changed 3D graphics settings prefer to nvidea driver and problem fixed i have problem and can't understand what is matter. i am creating simple GUI window and putting JTextField object on it. when i run project and enter text in text field it does not displays properly. i already tryed to reinstal java, but can't fix problem. can anyone help me? here is my GUI window image here is my code (no exception thrown, nor error