Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving a Component from a SplitPane  RSS feed

 
Joel Cochran
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write my first real Swing Application. I have a JFrame with a JMenuBar, JToolBar, and a JSplitPane. I have JToolTips, JMenuItems, ActionListeners, the works.
Now I want one of the action listeners to update a JLabel on a JPanel on the left side of the JSplitPane.
I have found the JSplitPane.getLeftComponent() method but I seem to be at a loss as to how I actually make it work. I can't instantiate a Component, but if I try:

the compiler says that they are incompatible types.
I'm sure this is a simple question, like casting or something, but I am simply stumped.
After I accomplish this, how do I get my JLabel out of the JPanel and update it?
All the books show you how to build this stuff but don't seem to do a very good job telling you how to manipulate it once it's out there!
Thank in advance,
 
cardwell cupp
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you are having fun! I believe that a JPanel extends from a JComponent which also extends from a Component, so you could type cast it:
JPanel left = (JPanel)splitPane.getLeftComponent();
But I see that you want to get a JLabel out of the left pane. Where did you put the JLabel?
If you instaniated it and it is member of you class, you can just acces it that way. I am not sure how to get it otherwise...?
Did you ?
private JLabel label = new JLabel ("text");

or

leftPane.add(new JLabel("text"));
Cardwell
 
Joel Cochran
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks CC, that did it!
I knew it had to be something simple... I think by the time I wrote the message I was severly brain fried!
As far as the updating, I may have to simply clear the existing JLabel and replace it with a new one. Here is the code used to create the splitPane...

Now that I have retrieved the leftComponent that I would be able to change it's properties? I may not be using the right components yet, just started seriously messing with this stuff on Tuesday.
 
Joel Cochran
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jus tin case anyone is curious I found a far simpler way to accomplish this.
If I define every component as a private instnace variable, then I never have to worry about retrieving a component from within another component to update it, I need only refer to it directly...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!