Re: JTable size

Discussion in 'Java' started by John B. Matthews, May 8, 2012.

  1. In article <>, Hakan <>
    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(newtdim);


    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>
    John B. Matthews, May 8, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tivo Escobar
    Replies:
    1
    Views:
    7,309
    manusa
    Apr 12, 2007
  2. Yulia
    Replies:
    1
    Views:
    671
    Andrew Thompson
    Jul 4, 2005
  3. Tintin92
    Replies:
    1
    Views:
    1,694
    Andrew Thompson
    Feb 14, 2007
  4. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,559
    Michael Jung
    May 25, 2008
  5. Haircuts Are Important
    Replies:
    3
    Views:
    312
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page