documentlistener

JTextArea updated with DocumentListener

泄露秘密 提交于 2021-01-28 01:21:21
问题 JTextArea area1 = new JTextArea(); JTextArea area2 = new JTextArea(); DocumentListener documentListener = new DocumentListener() { public void changedUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } public void insertUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } public void removeUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } private void printIt(DocumentEvent documentEvent) { DocumentEvent.EventType type = documentEvent.getType(); String

trouble passing input from one JTextArea into another JTextArea

流过昼夜 提交于 2020-01-17 09:28:09
问题 My issue lies in my DocumentLister AreaListener. I can't seem to figure out how to pass in the text the user enters into one of the JTextAreas for my conversions and return it to the other JTextArea. The goal of the program is to take in a user entered Roman or Arabic Number in one of the fields, convert it and return the value of the conversion to the other field in real time. My GUI and conversion methods work, I just can't seem to wrap my head around obtaining that string from the user and

Binding of JText fields value to Info Class

时光怂恿深爱的人放手 提交于 2020-01-04 06:39:10
问题 Is there any way to automatic binding of Swing JTextFields to Info Class. e.g private JTextField receiptId; private JTextField Id; public class Info { private string receiptId; private String id; // Getters and Setters } Is there any way when I entered values from Swing page then automatically values bind with my Info class? After that I can pass my Info object to other classes instead of sending all Text Fields. 回答1: This 'binding' is typically done using a DocumentListener. Call your

How to get JTextField name in which is Document placed?

狂风中的少年 提交于 2019-12-29 08:04:28
问题 Is there something like event.getSource for DocumentListener too? Im trying to change color of just one JTextField in which is text changing. Here is my DocumentListener: DocumentListener posluchac = new DocumentListener() { public void changedUpdate(DocumentEvent e) { warn(e); } public void removeUpdate(DocumentEvent e) { warn(e); } public void insertUpdate(DocumentEvent e) { warn(e); } public void warn(DocumentEvent e) { txtName.setBackground(Color.WHITE); txtSurname.setBackground(Color

Interacting with multiple textfields with KeyListener for Java

帅比萌擦擦* 提交于 2019-12-25 03:47:06
问题 I'm making a small java program where I have two JTextFields labeled field1, field2. I have a calculate button as well which initially set to disabled. I want the button only to be enabled when the 2 text boxes have values in them. Currently what i have for the key listener is: field1.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { if (field1.getDocument().getLength() > 0) { bt1.setEnabled(true); } else { bt1.setEnabled(false); } } });

documentlistener with invokelater goes infinite loop

最后都变了- 提交于 2019-12-24 15:53:32
问题 I have a Jpanel with textfield. I am using documentListener to save the changes as the user types in the text field. User can type between 1-1000, if he types anything else, there would be a error message pop-up. Now, I am using invokeLater, but that causes the infinite loop, if the user enters >1000. How can I fix this. mMaxLabelLength = new JTextField(); mMaxLabelLength.getDocument().addDocumentListener(this); @Override public void changedUpdate(DocumentEvent arg0) { } @Override public void

Getting indirect source of DocumentListener

匆匆过客 提交于 2019-12-24 09:26:42
问题 I have a document listener, and it's indirect source, JTextArea (JTextArea.getDocument().addDocumentListener etc..). I need my listener to have access to JTextArea, but without referencing. Something similar to event.getSource() from action and key listeners... I'm aware that the source of the listener is the document, not JTextArea itself, but I need to get to it. Any suggestions? 回答1: A Document is the model of a text component, and Swing is built for a single model to be able to be used by

message console Java

跟風遠走 提交于 2019-12-24 04:54:08
问题 I have the code to this open source Message Console in java, but it simply won't compile. Can anyone see if it is operational using their IDE? import java.io.*; import java.awt.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; /* * Create a simple console to display text messages. * * Messages can be directed here from different sources. Each source can * have its messages displayed in a different color. * * Messages can either be appended to the console or

JTextField listener when text changes that modifies textField's text

时光总嘲笑我的痴心妄想 提交于 2019-12-22 10:26:36
问题 Any idea how I can add a text listener on to a JTextField, that triggers when the text changes and as an action modifies the JTextField's text. I have tried using addInputMethodListener which seems to be appropriate but it doesn't seem to work. I have also tried textField.getDocument().addDocumentListener() but this throws java.lang.IllegalStateException: Attempt to mutate in notification when I try to modify textField's text. 回答1: DocumentListeners do not permit the modification of the