• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to refresh a JFrame containing a JPanel with lots of Components

 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m unable to refresh the JFrame , as the JFrame is consisting JPanel with few components on it. In that JPanel , I have added a JComboBOx , which should be updated as soon as the user update any value for the JComboBox. I am adding a piece of my Code-





I have already tried with validate(),repaint() , it may possible that i didnt work that one perfectly.
 
Campbell Ritchie
Marshal
Posts: 52549
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Please use the code button for youir posts, rather than coloured text, which is hard to read. I have added code tags for you.

The methods of JComboBox which add or remove items don't work? Are there any Listeners on the JComboBox?
What is the bit about compareTo("New...") supposed to do? That will fail unless you pass "New..."

Otherwise, don't know. Maybe somebody else will be able to help.
 
Campbell Ritchie
Marshal
Posts: 52549
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And have you forgotten to close your BufferedWriter?
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right..Guess....Today is the 1st Day...in CodeRanch.will follow the standards..[try to]


My main concern is to update or refresh the entire JFrame.
JFrame consists a JPanel containing a total of 8 diff components. I want to refresh the whole JFrame so that the listener could update the data.

 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right..Guess....Today is the 1st Day...in CodeRanch.will follow the standards


And while you're at it, learn Java coding standards. Variable names are not capitalized. I've never seen a text book or tutorial use capitalized names so why are you?

If you want to refresh a component then just use the "setText" (or equivalent) method of the component. There is no need to create new Components every time just to change its value.

If you are creating brand new components then you need to use "panel.revalidate()" after adding the components to a panel.
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I only posted a very small part of the Code..the code is actually like..I am allowing the user to enter the any Name to e added in the JComboBox , then I write that string into a file , an in the code , the JComboBox values are being fetched through the FileReader scenario , exactly I only want to update this particular Field after updting the File , but I am not sure is it possible here or not.


 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I only posted a very small part of the Code..the code is actually like..I am allowing the user to enter the any Name to e added in the JComboBox , then I write that string into a file , an in the code , the JComboBox values are being fetched through the FileReader scenario , exactly I only want to update this particular Field after updting the File , but I am not sure is it possible here or not.


Thanks, Issue Solved

 
Campbell Ritchie
Marshal
Posts: 52549
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
buntha Choudhary wrote:Thanks, Issue Solved
Please tell us how you solved it. That might be useful for other people in the future.
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I used the Revalidate() option..didnt require the Repaint();
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!