Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Re: JTable size (http://www.velocityreviews.com/forums/t946050-re-jtable-size.html)

John B. Matthews 05-08-2012 04:13 AM

Re: JTable size
 
In article <1336376488.66@user.newsoffice.de>, Hakan <H.L@softhome.net>
wrote:

> What do I need to add to control the size of a JTable? Nothing
> happens when I run the code quoted below, it stays the same size.
>
> Dimension tabledim=proTable.getSize();
> tabledim.setSize(2*tabledim.getWidth(), tabledim.getHeight());
>
> proTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF) ;
> proTable.setPreferredSize(tabledim);
> Dimension newtdim=new Dimension();
> newtdim.setSize(2*tabledim.getWidth(), tabledim.getHeight());
> proTable.setPreferredScrollableViewportSize(newtdi m);


Absent a complete example, it's hard to say with certainty. What is the
goal? What is the expected value of getWidth() when you double it. Are
you constructing GUI components on the event dispatch thread? What is
the layout of the enclosing Container? At what point do you pack() the
enclosing Window? For reference, you might compare what your doing with
this working example:

<http://stackoverflow.com/a/8320681/230513>

In general, you should not use setPreferredSize() in this way, and you
cannot rely on a component's size until it has been validated. You may
get some insight from the answers to this question:

<http://stackoverflow.com/q/7229226/230513>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>


All times are GMT. The time now is 07:11 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.