jtextfield

How to set the width of a JTextField at runtime?

心不动则不痛 提交于 2020-01-21 12:14:29
问题 Can someone please help me how to set the width of a JTextField at runtime? I want my text field to be resized on runtime. It will ask the user for the length, then the input will change the width of the text field. if(selectedComponent instanceof javax.swing.JTextField){ javax.swing.JTextField txtField = (javax.swing.JTextField) selectedComponent; //txtField.setColumns(numInput); //tried this but it doesn't work //txtField.setPreferredSize(new Dimension(numInput, txtField.getHeight())); /

How to set the width of a JTextField at runtime?

谁说我不能喝 提交于 2020-01-21 12:14:07
问题 Can someone please help me how to set the width of a JTextField at runtime? I want my text field to be resized on runtime. It will ask the user for the length, then the input will change the width of the text field. if(selectedComponent instanceof javax.swing.JTextField){ javax.swing.JTextField txtField = (javax.swing.JTextField) selectedComponent; //txtField.setColumns(numInput); //tried this but it doesn't work //txtField.setPreferredSize(new Dimension(numInput, txtField.getHeight())); /

Java-How to extend InputStream to read from a JTextField?

心不动则不痛 提交于 2020-01-21 12:13:06
问题 Working on a project I got into running java applications through a small console-like window. Thanks to the wonderful community in here I managed to solve the problem with outputting the data from a proccess but my command-line applications running will constantly give errors as there is no input stream. Based on the last helpful reply in that thread I suppose I shall approach similarly the JTextFieldInputStream extends InputStream implementation, but looking in the javadocs and throughout

How can I disable the textfield area of JSpinner

空扰寡人 提交于 2020-01-17 12:26:32
问题 I'm currently having a problem in netbeans where my JSpinner is allowing you to type in the textfield while I only want the arrows to be used. Is there a way to disable the input of text via properties or some other way? Thanks 回答1: Disable the JSpinner's JTextField's using the following: ((JSpinner.DefaultEditor) yourSpinner.getEditor()).getTextField().setEditable(false); 回答2: You can try it like this JSpinner.DefaultEditor editor = ( JSpinner.DefaultEditor ) component.getEditor(); editor

How can I disable the textfield area of JSpinner

≯℡__Kan透↙ 提交于 2020-01-17 12:24:25
问题 I'm currently having a problem in netbeans where my JSpinner is allowing you to type in the textfield while I only want the arrows to be used. Is there a way to disable the input of text via properties or some other way? Thanks 回答1: Disable the JSpinner's JTextField's using the following: ((JSpinner.DefaultEditor) yourSpinner.getEditor()).getTextField().setEditable(false); 回答2: You can try it like this JSpinner.DefaultEditor editor = ( JSpinner.DefaultEditor ) component.getEditor(); editor

How to check JTextField text to String?

风格不统一 提交于 2020-01-17 07:47:14
问题 I have a problem on checking the text and string. public boolean Isequals(Object c){ boolean check = false; if (c instanceof MyTextTwist){ MyTextTwist tt = (MyTextTwist)c; if (txtGuessPad.getText().equals(answer)) check = true;} return check; } this what i have so far. 回答1: Since your question is not very clear, i suggest these answers: 1st option - you want to get string from your JTextField: String text = txtGuessPad.getText(); 2nd option - you want to check if text contains only letter:

Accented characters in JTextField

会有一股神秘感。 提交于 2020-01-17 03:30:30
问题 I'm making an application where I use JTextField to connect to something (in this case, a database), but when I try to do so with the good login/password, it doesn't work, because some special characters become wrong characters. example: ç become a Greek letter, é become ù, etc . . . I think it's a charset problem, but I couldn't find how to fix it. My code looks like this: JTextField login = new JTextField(); JTextField passw = new JTextField(); JButton connect = new JButton("Connect");

Two KeyListeners on JTextField

我的未来我决定 提交于 2020-01-17 01:29:08
问题 Is it a good practice to add few listeners for JComponent in different part of code? Should I create one bigger listener? For example I have JTextField, I noticed that both KeyListeners are called. JTextField textField = new JTextField(); textField.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { something(); } }); textField.addKeyListener(new KeyListener() {

automatic dynamic expansion / contraction of JTextArea in Java

£可爱£侵袭症+ 提交于 2020-01-15 08:56:07
问题 I start off by creating a JTextArea of a specific size. The user can add text within it but it will get cut off if it becomes too long (vertically or horizontally). I want the JTextArea to automatically expand or contract (for deletion of text). I may allow users to change font and font size in the future, so it would be good if I could avoid making things increase/decrease by a certain size. I am currently using bounds to size my JTextArea. Perhaps I should size by rows and columns and use a

Java, Swing: how do I set the maximum width of a JTextField?

落爺英雄遲暮 提交于 2020-01-13 08:19:05
问题 I'm writing a custom file selection component. In my UI, first the user clicks a button, which pops a JFileChooser ; when it is closed, the absolute path of the selected file is written to a JTextField . The problem is, absolute paths are usually long, which causes the text field to enlarge, making its container too wide. I've tried this, but it didn't do anything, the text field is still too wide: fileNameTextField.setMaximumSize(new java.awt.Dimension(450, 2147483647)); Currently, when it