我想形成一个嵌套表,但是看起来这些列之间有很大的空间。请感谢任何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();
}
}
您需要控制第一个表的首选大小:
JTable jt2=new JTable(data0,columnA1);
jt2.setPreferredScrollableViewportSize(jt2.getPreferredSize());
现在,第一个表的高度将只是标题的高度。