This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

retrieving values from JTabbedPane  RSS feed

 
kavya bharadwaj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...

I m adding into my JTabbedPane several contentPanes. I need to access the JList in one of those content panes. I m adding into JTabbedPane as:

public JTabbedPane tab=new JTabbedPane();
tab.add("NAME",frame.getContentPane());

please suggest on how i can access my JList inside the tab. thanks in advance.
 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kavya bharadwaj:
public JTabbedPane tab=new JTabbedPane();
tab.add("NAME",frame.getContentPane());

1) use addTab instead, it's more intuitive then just adding to the tabbed pane. add calls insertTab in the end just like addTab, but it makes it more clear you are adding a tab.

2) are you adding the content pane of your current frame to the tabbed pane?? You know that components can have only one parent, right? This way, the frame will be content-pane-less!


If you use addTab or insertTab, you can use getTabComponentAt to return the component you have added. If that's a JList directly it's easy, otherwise you'll have to extract the JList from the component. You can use the getComponents method for that.
 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just like Rob Prime said, or you could make your own class for each tab component (like extend from JPanel...) and make your JList as a local variable and then accessing to this list is easy through some get method.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I need to access the JList in one of those content panes.

how would you do it if you just had the frame/contentPane?
(forget about the tabbedPane for the moment)
 
kavya bharadwaj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks i could do it using get components and instance of methods. how ever i have one small issue.

i m using the following loop to get values of all rows of a JTable which uses a DefaultTableModel
I m not able to retrieve the last row data while others are retrieved. could anyone tell me why..

for(int g=0;g<table.getRowCount();g++)
{
System.out.println( table.getValueAt(g,1));
}

thanks in advance.
>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!