如何最小化columnA1 []和columnA2 []之间的长度,使其看起来像一个嵌套表?

问题描述 投票:-1回答:1

我想形成一个嵌套表,但是看起来这些列之间有很大的空间。请感谢任何HLP或评论

public class NextDayDeliveryTable {



    JFrame frame;
    public NextDayDeliveryTable(){
        frame=new JFrame();


        String columnA1[]={"Document (below 2kg)","Parcel (above 2kg)"};
        String columnA2[]={"First 500gm","Subsequent 250gm","2.001-2.5kg","Subsequent 500gm"};
        String data1[][]={ {"4.90","0.80","10.50","0.50"},
                {"5.40","1.00","16.00","2.00"},{"6.90","1.50","21.00","3.00"},{"7.40","1.50","26.00","3.50"},{"7.90","2.00","31.00","4.00"},
        };
        String data0[][]={};



        JTable jt2=new JTable(data0,columnA1);
        JTable jt=new JTable(data1,columnA2);


        JScrollPane sp2=new JScrollPane(jt2);
        JScrollPane sp=new JScrollPane(jt);

        frame.add(sp2,BorderLayout.NORTH);
        frame.add(sp, BorderLayout.CENTER);
        frame.setSize(600,200);
        frame.setVisible(true);
    }
    public static void main(String[] args) {
        new NextDayDeliveryTable();
    }
}
java swing jtable
1个回答
0
投票

您需要控制第一个表的首选大小:

JTable jt2=new JTable(data0,columnA1);
jt2.setPreferredScrollableViewportSize(jt2.getPreferredSize());

现在,第一个表的高度将只是标题的高度。

© www.soinside.com 2019 - 2024. All rights reserved.