jtextfield

jbuttons and a jtextfield that has an action listener

£可爱£侵袭症+ 提交于 2019-12-11 12:28:45
问题 I have a keypad made up of jbuttons and a jtextfield that has an action listener. When I press the button the number shows in the textfield but the next number overwrites it. Could anyone tell me how to append the text to the length 13 numbers and when it get's there to carriage return. If I use the keyboard to enter numbers I can enter a String of numbers but not from the buttons. I am using: JButton buttonNo2 = new JButton("2"); buttonNo2.addActionListener(new ActionListener() { public void

Perform action upon completion of barcode scanning to JTextField

血红的双手。 提交于 2019-12-11 11:58:58
问题 I have a JTextField barcodeTextField which accepts characters from the scanned barcode using a barcode scanner. From what I know, barcode scanning is like typing the characters very fast or copy-pasting the characters on the text field. barcodeTextField is also used to show suggestions and fill up others fields with information (just like searching in Google where suggestions are shown as you type). So far I implemented this using DocumentListener : barcodeTextField.getDocument()

How can I output only a certain number of digits after a decimal place in a JTextComponent?

被刻印的时光 ゝ 提交于 2019-12-11 11:53:50
问题 I am using both JLabel s and JTextField s, and need to be able to truncate my doubles to two decimal places when they are displayed by the application. How can I perform this truncation, preferably without switching to JFormattedTextField s? 回答1: You can use DecimalFormat class. Here is an explanation 回答2: Prefer the Swing JFormattedTextField instead; see the Java Tutorial. 来源: https://stackoverflow.com/questions/2525492/how-can-i-output-only-a-certain-number-of-digits-after-a-decimal-place

JTextField with regex applied won't accept value until AFTER the Document is applied

早过忘川 提交于 2019-12-11 11:00:58
问题 I have a JTextField that I have overridden the Document for, so that I can prevent the user from entering some characters. The way this works is my extension of Document receives a Regex in its constructor, then checks anything the user types against the Regex: public class ValidDocument extends PlainDocument { private String regex; public ValidDocument(String regex) { this.regex = regex; } @Override public void insertString(int offs, String str, AttributeSet a) { if(str == null) return; try

JTextField accept only valid unsigned Shorts? (Using KeyAdapter)

柔情痞子 提交于 2019-12-11 09:51:22
问题 Below is the KeyAdapter I tried to get working to only accept values less than 65535. It seems as though it gets it one keystroke behind where it actually should. For example, If I type "55", the System.out.println will yield "5", doing "3298" will yield "329", etc. // Allows for unsigned short values only KeyAdapter unsignedShortAdapter = new KeyAdapter() { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); int tempInt = 0; JTextField temp = null; if (!((Character.isDigit(c) || (c =

How to mdify the computeBalance() method making sure that amounts are positive and without cents?

拟墨画扇 提交于 2019-12-11 09:23:02
问题 How do I modify computeBalance() making sure that the amounts enetered in the JTextField is positive ( which I think I did) and is without cents? Example: 100.19 and -49.8 is not acceptable. public class ATMbizlogic { private double totalBalance; private boolean rightPinEntered; /** * Creates a new instance of ATMbizlogic */ public ATMbizlogic() { totalBalance = 0.0; rightPinEntered = true; } public void computeBalance(double withdraw, double deposit) throws ATMexception { if(withdraw <=0)

Filtering a JTextField for strings, space and a dot (.) using a DocumentFilter

烈酒焚心 提交于 2019-12-11 08:59:05
问题 I have a JTexTField that I would want a user to enter the name of a person. I have figured that the name should contain [a-zA-Z] , . and space example Mr. Bill . I am using a DocumentFilter to validate user input.However, I cannot figure out how should I set this within my DocumentFilter . Question: How should I modify my filter to achieve the above behavior? Any suggestion on how to validate a person's name is accepted. Here is my DocumentFilter: public class NameValidator extends

InputVerifier don't display each component icon(lable)

回眸只為那壹抹淺笑 提交于 2019-12-11 08:56:54
问题 I have a form that set a input verifier to it. I want when a user type a correct value for a text field and want to go to other text field, a check icon should be display besides of text field. But now in my code, when user type a correct value on first text field an go to other, Two icons displayed together! public class UserDialog extends JDialog { JButton cancelBtn, okBtn; JTextField fNameTf, lNameTf; JRadioButton maleRb, femaleRb; ButtonGroup group; JLabel fNameLbl, fNamePicLbl, lNameLbl,

setVisible(false) to a group of JTextField and JLabel

与世无争的帅哥 提交于 2019-12-11 08:46:01
问题 I have a group of JTextField and JLabel . I want them to initially not be visible so I thought to initialize my applet with a method which calls setVisible(false) for each of the components. Is it possible to create a method setVisible(false) which will set the visibility of all the components to false. Finally if I have 40 components in the applet, is it possible to do this with only one command instead of 40 commands? 回答1: Add your buttons and labels to a JPanel and then you can simply make

JTextField in JDialog retaining value after dispose

十年热恋 提交于 2019-12-11 08:19:20
问题 I'm having a JTextField problem. I am needing to get text from a JTextField and modify it later in a JDialog. I am using the same variable for the JTextField. As long as you don't enter the dialog, the string printed is whatever you entered in the text field. If you enter a string in the dialog, it will only print that string until you change it again in the dialog (renders the primary text field useless). I can fix this by adding a separate variable, but would like to try to avoid