Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextField & repaint issues.

 
Roy Pozarelli
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Peters
Ranch Hand
Posts: 67
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please provide a full working example. I tried what you did, but I don't get problems with the following code:

 
Bobby Smallman
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roy Pozarelli
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to hear it! :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic