jtextfield

swing: appropriate Listener for JTextField change events

点点圈 提交于 2019-12-04 02:14:38
Which type of Listener do I use for listening to changed text events in a JTextField ? (I should know this or be able to tell from the Javadoc but I can't seem to figure it out.) Use the underlying document: myTextField.getDocument().addDocumentListener(); 来源: https://stackoverflow.com/questions/2165071/swing-appropriate-listener-for-jtextfield-change-events

How can I add padding to a jtextfield

空扰寡人 提交于 2019-12-03 22:30:03
How can I add some padding to a jtextfield? I've tried tf.setMargin(new Insets(5,5,5,5)); which doesn't have any effect. The problem you are having is that the UI is setting its own border on the text field, overriding the margin you set. You can see a warning to this effect in the javadoc of setMargin() . The solution is to let the UI set a border, then squeeze in another border of your own: field.setBorder(BorderFactory.createCompoundBorder( field.getBorder(), BorderFactory.createEmptyBorder(5, 5, 5, 5))); you have look at CompoundBorder , there you can set LineBorder(Color.gray, 1) and with

how to filter certain characters in JTextField

时光毁灭记忆、已成空白 提交于 2019-12-03 18:16:35
问题 How to prevent user from entering certain charcters in 'JTextField' and if enters that character is entered ,do not show it in the textfield 回答1: JTextField textField = new JTextField(10); textField.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (//Write your condition here) { e.consume(); // ignore event }}); More on the same here 回答2: You can either use a JFormattedTextField or create a custom DocumentFilter. 来源: https://stackoverflow.com

Disabling 'paste' in a jTextfield

社会主义新天地 提交于 2019-12-03 16:19:42
I have an app that is written in Swing, awt. I want to prevent users from pasting values into the textfields. is there any way to do this without using action listeners? You can just call setTransferHandler with a null parameter like this: textComponent.setTransferHandler(null); This will disable all copy/paste actions on the field. The best way is to remove action associated with CTRL+V keystroke in components ActionMap. Rob The simplest way it to say: textComponent.setEditable(false); This disables cut & paste, but copy is still enabled. public class PastlessJTextField extends JTextField {

Hide/Show Password in a JTextFIeld (Java Swing)

隐身守侯 提交于 2019-12-03 11:38:10
问题 So I've been working on a Password Strength Checker and the way it works is that the user enters some random text into a textfield and then instantaneous visual feedback (breakdown of points) is displayed. I've also added a checkbox, which on being selected, should hide the password i.e. replace all the chars with asterisks, while preserving the actual text input by the user. A document listener is being used to keep track of changes inside the textfield. (each char on entry gets analyzed and

Auto filling a jTextfield in java swing

故事扮演 提交于 2019-12-03 00:47:21
问题 I am creating a small system using swing via netbeans(I must say i am new to swing). look at the below image . in this the id = "ST100" i need to add it to a jTextfield automatically in the below interface when i open it so i coded it in the first interface source code as seen below after making the arrowed textfield's access modifier "public" which is in the second interface. but the wanted text is not auto filling why is it? the relevent code in the first interface addSubjects add = new

how to manipulate JTable return value on specified column?

女生的网名这么多〃 提交于 2019-12-02 21:59:19
问题 I have a JTable that has two columns ( editable JTable ). When a user types something in the second column, my requirement is as follows: user can only typewrite a number and comma when user type wrong character, it will beep (Toolkit.getDefaultToolkit().beep(); ) How do I go about achieving this? ( if it jtextfield it need document filter or plain document etc, if it JTable, then how? ) 回答1: Implement a TableCellEditor that is capable of returning a text component ( JTextField ) that has a

how to populate all items in JTable when corresponding JTextfield is empty

我是研究僧i 提交于 2019-12-02 20:26:06
问题 I am designing a advanced search option in a Java project with sqlite in NetBeans. There are 5 different JTextfields and 5 columns, I want to populate JTable with corresponding matching criteria. If a JTextfield is empty then it should select all items of that column. Query I was using is: String val1 = txt_billing2.getText(); String val2 = txt_station2.getText(); String val3 = txt_invoice2.getText(); String val4 = txt_amonth2.getText(); String val5 = txt_umonth2.getText(); String sql =

JLabel and JTextField setText is not update

我的梦境 提交于 2019-12-02 18:09:37
问题 I want to update jlabel and jtextfield with setText() method but it is not working. However, rest of the code is working. The code is below; btnDosyaSe.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int kullaniciSecimi = jfc.showOpenDialog(null); if (kullaniciSecimi == JFileChooser.APPROVE_OPTION) { File fileName = jfc.getSelectedFile(); textField.setText

Force JTextField to string value while DocumentFilter only allows digits

让人想犯罪 __ 提交于 2019-12-02 17:01:14
问题 I'm working on a Java application and ran into a problem that I cannot seem to solve on my own. I've set a DocumentFilter on JTextField to only allow digit entries, however, the default values are text. I have a button that resets JTextField s back to default, and it is not working presumingly because of the DocumentFilter . How can I overcome this problem? Thanks 回答1: A field that the user can only enter numeric data into, but also needs to display non-numeric values is contradictive. Text