jtextfield

JComboBox does not behave same as JTextField. How can i have it look similar?

偶尔善良 提交于 2019-12-11 01:35:04
问题 I have this following combo box, where i am able to create my combo box with items etc, but the look is not same as JTextField. How can i make JCombobox look same like JTextField? MyComboBox.java: import java.awt.Color; import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.LineBorder; import javax.swing.plaf.basic.BasicComboBoxUI; public class MyComboBox extends JComboBox { public MyComboBox(String[] name) { Border border = BorderFactory.createEmptyBorder(11, 11,

Listening to many JTextFields and calculate value sum in a Row

余生长醉 提交于 2019-12-11 01:27:50
问题 I have an application that gets input from user; it has 8 rows of JTextFields with 3 columns: +-----------+-----------+-----------+ | Field 1-1 | Field 1-2 | Field 1-3 | +-----------+-----------+-----------+ | Field 2-1 | Field 2-2 | Field 2-3 | +-----------+-----------+-----------+ | Field 3-1 | Field 3-2 | Field 3-3 | +-----------+-----------+-----------+ In each row while user changes first or second field the sum of new values must be written in third field. For example when user changes

How to globally change the ActionMap of Swing JTextFields?

让人想犯罪 __ 提交于 2019-12-10 23:57:17
问题 I want to change the ActionMap of Swing JTextFields in my entire Application by replacing a few actions by my custom implmentations. For an explanation why you can refer to the following post: How do I make the caret of a JTextComponent skip selected text? This works well if I do this: ActionMap map = (ActionMap)UIManager.get("TextField.actionMap"); map.put(DefaultEditorKit.backwardAction, new MyCustomAction()); The only remaining problem now is that so far I have only gotten this to work,

JTextField in JToolbar - cannot display properly in both Linux and Windows

五迷三道 提交于 2019-12-10 22:45:31
问题 Please see the SSCCE below: import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.EventQueue; import javax.swing.Box; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JToolBar; import javax.swing.UIManager; import javax.swing.border.EtchedBorder; @SuppressWarnings("serial") public class GlueTest extends JComponent { private JFrame frame; private JToolBar toolbar;

Undo in JTextField and setText

耗尽温柔 提交于 2019-12-10 19:49:08
问题 JTextField has an undo support out of box. It works fine for user interacion, but unfortunately if method setText(String str) is called, that results two UndoableEdits instead of one. So this code looks and feels fine but does not work: UndoManager undoManager = new UndoManager(); JTextField tf = new JTextField(); tf.setText("initial value"); tf.getDocument().addUndoableEditListener(undoManager); tf.setText("new value"); undoManager.undo(); System.out.println(tf.getText()); // Prints empty

how do i limit the length of the input i want inside a Jtextfield?

▼魔方 西西 提交于 2019-12-10 18:45:54
问题 username = new JTextField(""); username.setBounds(330, 550, 230, 30); username.addActionListener(this); username.requestFocus(); // sets focus on JTextField this.add(username); 回答1: JTextField username = new JTextField("") ; final int limit = 10; username .setDocument(new PlainDocument(){ @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if(getLength() + str.length() <= limit) super.insertString(offs, str, a); } }); 来源: https:/

GUI Trouble reading JTextField

懵懂的女人 提交于 2019-12-10 16:27:52
问题 I can't figure out where I am going wrong with this, I have tried to changing a few things but I just can't get the "CalculateButtonHandler to work correctly. Sorry put out all this code but last time I wasn't specific enough :S If someone could point me in the right direction that would be great. Thanks. import javax.swing.*; import java.awt.*; import java.awt.event.*; // some kind of problem with Calculate button handler (LINE 78 public class Program5 extends JFrame { // Setting up for the

Select all text in editable JComboBox and set cursor position

心不动则不痛 提交于 2019-12-10 14:35:42
问题 public class CursorAtStartFocusListener extends FocusAdapter { @Override public void focusGained(java.awt.event.FocusEvent evt) { Object source = evt.getSource(); if (source instanceof JTextComponent) { JTextComponent comp = (JTextComponent) source; comp.setCaretPosition(0); comp.selectAll(); } } } jComboBox.getEditor().getEditorComponent().addFocusListener(new CursorAtStartFocusListener()); As you see from code above I want to select all text in editable JComboBox and set cursor position to

Java Swing JtextField inset

一个人想着一个人 提交于 2019-12-10 13:58:20
问题 I am working with Netbeans GUI and I would like to add 3 pixels of space at the beginning of my jTextField : I have tryied with setMargin, setInset in the GUI but it doesn't change anything. I have another question, why the bottom right border is not rounded ? here is my code : Border roundedBorder = new LineBorder(new Color(210,210,210), 1, true); researchTextField.setBorder(roundedBorder); thank you very much, Regards 回答1: Using setMargin(...) should work. However, if you are also using a

JTextField - separation of numbers (ArrayList)

时光总嘲笑我的痴心妄想 提交于 2019-12-10 11:51:44
问题 Is there any way to take several different numbers using JTextField? For example, following numeric values are given: 2.0, 3.0, 4.0. I would like to put them into ArrayList separately. How to handle incorrect input data ​​in order to continue the typing? //in this case the resulst is "arList: 1.92239991" textField = new JTextField("1.9, 223, 9991"); textField.addActionListener(this); ArrayList<Double> arList = new ArrayList<>(); String str = textField.getText(); String result = str.replaceAll