• Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating JPanel

 
David Houghton
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, any help with this problem would be great. Im at a loss:

I have a calss which runs an instance of JFrame, with bordlayout set as the layout manager, in the center position i have a JPanel.

I have a second class which extends JPanel called PanelLoader, just for the purpose of keeping the code for this above mentioned JPanel seprate from my main class. The problem:

the constructor for PanelLoader basically adds a few swing components (labels text boxs etc.) on to a Jpanel and then returns the panel. The constructor works fin adn any pre defined text i have set is displayed with the text boxs. When i run the updatePanel method of my PathLoader class, the text property of the JTextFiled is being changed but the changes are not being reflected in the panel whic is returned.

Below is the code updatePanel() and the assignemnts for my panel on the main JFrame from my main class. Pleas help. Thanks

Dave







The argument for updatePanel contains the strings for the JTextFields to be updated
 
Paul Clapham
Sheriff
Posts: 21872
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But your updatePanel() method creates a new PanelLoader object. Why does it do that? Why doesn't it update the existing one, which presumably you have added to your JFrame?
 
David Houghton
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did try that paul with the code below but i am getting a syntax error, cannot find symbol. The variable as declared as public in the PanelLoader class:





The answer to your question would be i dont know how to. Relitivaly knew to Swing sorry.
 
Paul Clapham
Sheriff
Posts: 21872
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name of the method is "setText", not "settext". Case counts in Java.
 
David Houghton
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry thats just my typo on here, i have it correct in the code. Ive managed to narrow it down to a problem with the argument for updatePanel.

If i use a string argument rather than a String array, using an over written method of updaetPanel which takes a string argument, the method works fine, however this is not suitable for purpose

the 1st println statment prints what should be the correct string and the second confimrs the text attribute of adCounty has been updated. Dont know whats going on

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have static methods here? The only code that should be static in your program are your constants, your main method, and anything that absolutely has to be static. This JPanel should be an instance variable and the code that calls it and manipulates it should not be static. I think the problem here is not a GUI problem but a basic OOPs problem.
 
David Houghton
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pete thanks, have re-written my code. It wouldnt initiall let me call updatePanel without qualifying with class name. I just realised that i had declared the original instance of filePanel as an instance of JPanle rather than panel loader. I can now call the method from a non-static context.

Paul, the above problem was stopping me make the changes in my main calss but i can know do this as you suggested and all is fine.

Thank you both for the help and patientce

Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!