wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JTextField & repaint issues. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField & repaint issues." Watch "JTextField & repaint issues." New topic

JTextField & repaint issues.

Roy Pozarelli
Ranch Hand

Joined: Oct 17, 2009
Posts: 39
I have JDialog box that houses 3 JPanels , SearchPanel, DataPanel and ButtonPanel.
The SearchPanel houses a JLabel (searchLabel) and JTextField (mySearchField).
The DataPanel (myDataPanel) has several JComboBox's. I've added (sub-classed) ActionListener to the combo boxes that will take the selected object, process the data, and do a mySearchField.setText(theData) on the SearchPanel's JTextField.
The problem I seem to have is it does not seem to be repainted, i.e. the old text "Blank" is still there. I've tried repaint() on the JDialog, DataPanel, JTextField (all I could think of) as well as invalidate() and revalidate(). I'm not sure what to try next. I know I'm missing something, just can't figure out what. I've show the relevent code below (cut out the non-revelent parts). Any help is greatly appreciated!

At line 143, in the debugger (Eclipse) I can see that the mySearchField->model (PlainDocument)->data->array has the correct string from what was selected in the combo box. I've even added an
mySearchField.addActionListener(new ActionListener(ActionEvent ae) {...}); in the initSearchPanel() as well as a mySearchField.postActionEvent() in the FieldListeners actionPerformed() to know avail.

OCP Java SE 6 Programmer,
OCM Java SE 6 Developer
OCE Web Components
MySQL Certified Administrator & Developer,
OMG Certified UML Prof. Fund., Int., Adv.
Mike Peters
Ranch Hand

Joined: Oct 10, 2009
Posts: 67

Can you please provide a full working example. I tried what you did, but I don't get problems with the following code:

Mike Peters
Bobby Smallman
Ranch Hand

Joined: Sep 09, 2010
Posts: 107
I wasn't positive what you attempted exactly, it seems to me a just after line 142 should fix your problem. Is it my understanding you have already attempted that(or with revalidate) at that location and it still would not display the new string in your field? And you double checked that just after line 142 mySearchField does indeed hold the String you desire to display?

Everyday in every way, we get a little better.
Darryl Burke

Joined: May 03, 2008
Posts: 4523

validate() / invalidate() / revalidate() are all irrelevant in the context of setting the text of a JTextComponent. And repaint() isn't required.

To get better help sooner, post a SSCCE.

luck, db
There are no new questions, but there may be new answers.
Roy Pozarelli
Ranch Hand

Joined: Oct 17, 2009
Posts: 39
Thanks, got the solution, in building up the SSCCE (although it was becoming a LSCCE - long, which is why I didn't want to post it to begin with) it actually was a issue of duplicates - Singleton solved the problem.
Bobby Smallman
Ranch Hand

Joined: Sep 09, 2010
Posts: 107
Glad to hear it! :-)
wood burning stoves
subject: JTextField & repaint issues.
Similar Threads
JDialog- Multiple inputs
Center a JPanel in JScrollPane and add a JToolBar
JComboBox -how to have a empty item while implementing a model
Setting color in a JComboBox
How to navigate between multiple GUI classes