aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Creating jtable dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Creating jtable dynamically" Watch "Creating jtable dynamically" New topic
Author

Creating jtable dynamically

Harnoor Singh
Ranch Hand

Joined: Aug 24, 2010
Posts: 35
Hi,

I am working on project where we have requirement that we need to create different jtables based on number of number of users. One table will be ceated for each user. So if there are 10 users, then we need to create 10 jtables. Kindly let me know if it is technically feasible. I tried to start solving problem by first creating number of jtables in for loop. However problem is that how will i select the jtable name at runtime. Other problem I am coming across is that how will jtable fit in the jframe. If any one has worked with this kind of problem please provide inputs. Thanks in advance.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
just a thought...

add each table/scrollpane to a panel
add each panel to a CardLayout panel
add the CardLayout panel to a frame
add the userNames to a menu
link each menuItem to its respective user panel/table, via cardLayout.show(...)
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Better suitable on the GUI forum. Moving...


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Harnoor Singh
Ranch Hand

Joined: Aug 24, 2010
Posts: 35
Thanks Michael.

I want each table on the same jframe. Here is my approach to problem,, create jscrollpanes and jtables in for loop. Then add jtable to scrollpane. I am keeping all the jscrollpanes in one Map. Now how can i add these jscrollpanes to jframe.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18993
    
    8

You add 10, or 500, JTables to the frame in just the same way you'd add one of them. Make sure you've chosen a layout manager which is suitable for that, though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating jtable dynamically