This discussion is archived
8 Replies Latest reply: Jan 4, 2011 7:24 AM by 828405 RSS

JTable is not fit to the screen width.

804771 Newbie
Currently Being Moderated
JTable is not displayed to the full width of the screen.
I am using AUTO_RESIZE_OFF option in setAutoResizeMode(JTable.AUTO_RESIZE_OFF); API.
It makes the JTable to shrink fit to the screen and not fit to the entire width of the screen.

Any thoughts please to make the JTable to fit completely to the width of the screen?

Thanks in advance,
Rajakumar
  • 1. Re: JTable is not fit to the screen width.
    mKorbel Explorer
    Currently Being Moderated
    then you have to

    1/ .setPreferredWidth(int) for JTable Column (for each columns with different size)
    2/ .setWidth(int) for JTable Column (strict size)
    3/ and column should be still resiziable by mouse
  • 2. Re: JTable is not fit to the screen width.
    jduprez Pro
    Currently Being Moderated
    JTable is not displayed to the full width of the screen.
    I am using AUTO_RESIZE_OFF option in setAutoResizeMode(JTable.AUTO_RESIZE_OFF); API.
    It makes the JTable to shrink fit to the screen and not fit to the entire width of the screen.
    I'm sorry, I'm not sure I understand your question: the JTable will "fit" whatever size is awarded by the LayoutManager of its container. If the JTable has a preferredSize and the layout manager respects it (not all do), it will use it. If either don't, it won't. You do know about [url http://download.oracle.com/javase/tutorial/uiswing/layout/index.html]layout managers, don't you?

    Here is an SSCCE that demonstrates a JTable taking the whole space available in its frame, including when this latter is maximized to the screen width:
    public class TestJTableFitsScreenWidth {
    
        public static void main(String... args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                public void run() {
                    JFrame f = new JFrame();
                    DefaultTableModel dtm = new DefaultTableModel(
                            new String[][]{
                                new String[] {"A", "B", "D"},
                                new String[] {"D", "E", "F"}
                            },
                            new String[] {"col1", "col2", "col3"});
                    JTable table = new JTable(dtm);
                    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                    f.getContentPane().setLayout(new BorderLayout());
                    f.getContentPane().add(table, BorderLayout.CENTER);
                    f.setVisible(true);
                    f.pack();
                }
            });
        }
    }
    If I misunderstood your problem, please post an [url http://sscce.org]SSCCE that demonstrates the incorrect behavior, and please be more explicit about what should be the correct behavior.

    Regards,

    J.
  • 3. Re: JTable is not fit to the screen width.
    796262 Newbie
    Currently Being Moderated
    Please don't crosspost.

    Crossposted here: http://www.java-forums.org/awt-swing/33415-jtable-not-fit-screen-width.html

    And here: http://www.coderanch.com/t/513508/GUI/java/JTable-not-fit-screen-width
  • 4. Re: JTable is not fit to the screen width.
    DarrylBurke Guru Moderator
    Currently Being Moderated
    Cross posted
    http://www.coderanch.com/t/513508/GUI/java/JTable-not-fit-screen-width

    db

    edit
    http://www.java-forums.org/awt-swing/33415-jtable-not-fit-screen-width.html

    edit Drat, beaten here too!

    Edited by: Darryl Burke
  • 5. Re: JTable is not fit to the screen width.
    DarrylBurke Guru Moderator
    Currently Being Moderated
    Hey Kevin, you missed one ;)
    http://www.javaprogrammingforums.com/awt-java-swing/5528-jtable-not-fit-screen-width.html

    db
  • 6. Re: JTable is not fit to the screen width.
    804771 Newbie
    Currently Being Moderated
    I relatively new to this forum practice and hardly I posted 2 or 3 threads so far. I feel sorry for my unfair crossposting practice. I continue only at http://www.java-forums.org/awt-swing/33415-jtable-not-fit-screen-width.html#post148843
  • 7. Re: JTable is not fit to the screen width.
    828405 Newbie
    Currently Being Moderated
    I think i have a solution for yout problem. The unfilled table in the Mode AUTO_RESIZE_OFF is bug in Java.

    http://explodingpixels.wordpress.com/2009/05/18/creating-a-better-jtable/
  • 8. Re: JTable is not fit to the screen width.
    828405 Newbie
    Currently Being Moderated
    Here is another solution. i hope it works.

    http://www.jroller.com/santhosh/date/20050524#jtable_becomes_uglier_with_auto

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points