Results 1 to 7 of 7
Thread: JTable sizing issues
- 04-01-2011, 10:21 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 5
- Rep Power
- 0
JTable sizing issues
my program has a button which should delete a left-to-rght row in a table. however the problem is that JTables are not dynamically sized therefore in order to "update" the table i need to create a new table to match the now smaller size
the problem is that by creating a new table each time a user is deleted the Jframe is filled with the previous tables
how can i make my table dynamically sized to match the amount of rows needed?
-
have you tried yourContainer.pack() ?
- 04-02-2011, 01:49 AM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Why do you want to do that? The normal design approach is to pick a maximum size for the number of rows to display. The table is added to a scrollpane and the scrollpane is added to the frame. Then as you add/remove rows, the scrollbar will appear/disappear.how can i make my table dynamically sized to match the amount of rows needed?
Users don't like seeing the size of window continually changing.
- 04-02-2011, 01:58 AM #4
Member
- Join Date
- Apr 2011
- Posts
- 5
- Rep Power
- 0
what i want is to make sure there is no blank space at the bottom of the table.
container.pack(); isn't working cannot find variable
and i still need to implement a scrollbar for that table...
either way i can't figure out a way to change the row size without calling a new table each time
- 04-02-2011, 02:17 AM #5
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Given that you don't know that the pack() method is used on a frame and not a panel, this tells me you are a beginner GUI programmer.container.pack(); isn't working cannot find variable
As I said, that is NOT the way a UI is designed. Users don't want components shrinking and growing. Create the table at a reasonable size and let the scrollbars to the rest.what i want is to make sure there is no blank space at the bottom of the table.
To make the table look better you can try using:
Now the table will have a white background instead of the gray background.Java Code:table.setFillsViewportHeight(true);
- 04-02-2011, 02:25 AM #6
Member
- Join Date
- Apr 2011
- Posts
- 5
- Rep Power
- 0
the pack idea was given to me by the above poster but thats besides the point
i guess i need to implement a jScrollpane to see if that works.
EDIT: fixed the problem below me
problem is when ever i try that the JScrollPane(table) is just a sliver in size at the bottom of the frame
however nothing is appearing within the scrollpaneJava Code:JScrollPane scrollbar = new JScrollPane( table ); scrollbar.setPreferredSize(new Dimension(100, 200)); scrollbar.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollbar.setHorizontalScrollBarPolicy(JScrollPane .HORIZONTAL_SCROLLBAR_ALWAYS); scrollbar.add(table); frame.add(scrollbar, BorderLayout.SOUTH);Last edited by Timmins; 04-02-2011 at 02:31 AM.
- 04-02-2011, 02:40 AM #7
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Recommend you post an SSCCE demonstrating the problem. This help you break the problem down, and help us reproduce the problem at hand to help you. FWIW don't use add() to add components to a JScrollPane - use setViewportView(Component view) if you wish to set the view (the constructor does this by default - so no need for the add call)
And suggested reading:
How to Use Scroll Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)Last edited by doWhile; 04-02-2011 at 02:43 AM.
Similar Threads
-
Problem with JScrollPane/client sizing
By kennyman94 in forum AWT / SwingReplies: 1Last Post: 03-08-2011, 12:18 AM -
Panel sizing
By sjs in forum AWT / SwingReplies: 5Last Post: 10-11-2010, 03:13 AM -
Dynamically changing JPanel in a JScrollPane - incorrect sizing
By david.stefka in forum AWT / SwingReplies: 3Last Post: 02-06-2010, 03:28 PM -
Trouble with Buffer Sizing
By Jeff in forum New To JavaReplies: 3Last Post: 02-07-2008, 01:43 PM -
Help needed with sizing components
By adlb1300 in forum New To JavaReplies: 2Last Post: 11-20-2007, 04:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks