Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static JTextField problem!

 
Antigoni Splash
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a form for users to complete multiple of them and using some buttons can go back and front between forms... But i have a problem! I have some static fields that i want them to appear on every form and the changes made to them affect all forms, but when i go back to a previous form the fields appear for a sec and then leave immediately! That doesn't happen when i am moving forward...

Any ideas why is that?
 
Rob Camick
Ranch Hand
Posts: 2612
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Components can only have a single parent. You can't add the same component to more than one panel. It only appears like its working as you move forward because you don't see it being removed from the previous panel until you go back to that panel.

You should be able to create multiple components, but share the model. For example with a text field you can do:

 
Antigoni Splash
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh ok!
But is there a particular reason why a component canno't be added twice?
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Antriani,

Please read your private messages.

Thank you,

Rob
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> But is there a particular reason why a component canno't be added twice?

read the first sentence of the first reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic