jtextfield

Java JTextfields [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-11 08:05:20
问题 This question already has answers here : Is there any way to accept only numeric values in a JTextField? (19 answers) Closed 4 years ago . Just a quick question, How do i ensure my JtextField only accepts numeric values? I want it to to diplsy an error message if the user entered anything else thank you 回答1: You can use a JFormattedTextField. Construct it using a NumberFormatter and it will only accept numbers. The JFormattedTextField has a bunch of configurable options that let you decide

Mask the IP Address when the user enters in text field Java Swing

故事扮演 提交于 2019-12-11 07:38:06
问题 I have a JTextField to accommodate an ip address with 3 dots. 255.120.320.123. When the user enters this IP address, I want to mask it like . . . I was referring this thread, How to custom formatter JFormattedTextField to display an IP address? jFormattedTextField did not work for me. Can anyone give me an example with jFormattedTextField with 3 dots visible? Or do I need to use 4 jFomattedTextField / JPasswordField as mentioned in this thread? Thanks in advance. 回答1: Seems you need to use

Positioning GUI objects on a Frame

孤者浪人 提交于 2019-12-11 06:44:31
问题 I am developing a Java application and would like some help in positioning some Labels and TextFields. Here is my code: import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JComboBox; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JTextField; import java.awt.BorderLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.FlowLayout; public class AuctionClient { public AuctionClient(

Deleting last keystroke in JTextField if invalid

守給你的承諾、 提交于 2019-12-11 06:37:28
问题 Working on my 1st program. I figured out how to identify characters I do not want to be able to be inputted. I would like to know how do delete the last character entered so that from a user perspectvive it will appear as only numbers can be entered. @Override public void keyPressed(KeyEvent e) { char keyChar = e.getKeyChar();; char[] badCharArray = "abcdefghijklmnopqrstuvwxyz-`~!@#$%^&*()[]{}<>_+=|\"':;?/ ".toCharArray(); for (int i = 0; i < badCharArray.length; i++) { if (badCharArray[i] ==

TableCellEditor: clear original text if key is pressed; retain value if no input was givien

前提是你 提交于 2019-12-11 06:07:36
问题 I have here a code I found in the stackoverflow which allows the table to have a custom cell editor as JTextField . I have been reading some of the articles about cell editor and I understand some the behavior of each abstract method. class tableText extends AbstractCellEditor implements TableCellEditor { JComponent component = new JTextField(); public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,int rowIndex, int vColIndex) { ((JTextField) component)

Creating a text field that dynamically resizes its width

倖福魔咒の 提交于 2019-12-11 04:08:19
问题 I'm making what is basically a toolbar that contains a search field and some buttons. I'd like for the search field to grow in size (just the width) when the parent container gets wider, like when the user adjusts the split pane. Currently, the text field and the buttons will remain the same size and whitespace is added on either side as the container is widened. I can achieve this growing effect by using a BorderLayout in the container and putting the buttons on LINE_END and the text field

Java applet JTextField inaccesible after JDialog on Ubuntu

。_饼干妹妹 提交于 2019-12-11 04:02:47
问题 I have 2 problems with java on Ubuntu: JTextField gets inaccessible and you cant type anything in it. To reproduce you have to click on label ('Click this label') it will open my extended JDialog. After closing it with Cancel button JTextField gets inaccessible. The problem is that it doesen't happen all the time. I think around 1 on 10 tries. When it happens you have to click somewhere else on browser window or open dialog one more time. Second problem is that when ubuntu opens JDialog it

How to update JTextFields in a GridLayout?

痞子三分冷 提交于 2019-12-11 03:08:59
问题 I have a MainPanel which uses the Gridlayout . Consequently I have created four JPanel classes for the: NORTH, EAST, CENTER and EAST layouts respectively. I then add all four to my MainPanel . However, on my WEST panel I use another grid layout to store JButtons and JTextFields . I want to constantly update my JTextFields as they display a value (that changes when a button on another panel is clicked). How do I allow that value to be changed when the JFrame is running? I tried using

Getting data from JTextField that is one of several local variables

你。 提交于 2019-12-11 03:08:50
问题 So I am reading a file and I get the amount of lines in that file. Based on that I generate my interface. Now I need to have the ability to edit valus trougth UI . Rows is the variable that has how lines the input document has . Of course the code below doesnt work . I want to write new values to the array from which i read . for(int i=0;i<Rows;i++) { //System.out.println("!"+Symbol[1]+"!"); //if(Symbol[i]!=""&&Symbol[i]!=null) // { JTextField symbol = new JTextField(6); symbol.setText(Symbol

What's the purpose of JTextField setActionCommand() [how do you access it programmatically to find which cell an event occurred in?]

你。 提交于 2019-12-11 02:38:26
问题 ===EDIT MONTHS AFTER ORIGINAL POST=== The question was motivated by a need to know which cell of an 11x11 grid (array of JTextField) was active when a button was clicked. I had asked the wrong question and had chosen the wrong tool (setActionCommand), though it worked at the time via string manipulation. (I finally chose to completely rewrite what was a horribly-convoluted example of tortured code.) A better solution than using setActionCommand() is the Answer below that uses .setName(). ====