jscrollpane拖拽时出现重影
public class Selectgui2 {
JFrame f=new JFrame("text");
Container con = f.getContentPane();
JPanel p=new JPanel();
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JScrollPane jsp1=new JScrollPane();
JLabel ptop = new JLabel("信息查询");
JLabel p1top = new JLabel("在住客人列表");
JLabel p2top = new JLabel("预定客人列表");
JLabel p3top = new JLabel("历史客人列表");
public void init(){
p.setLayout(null);
p.setBounds(0, 0, 800, 145);
p.setBackground(new Color(233, 33, 00, 23));
p1.setLayout(null);
p1.setBounds(0, 145, 800, 555);
p1.setBackground(new Color(233, 33, 00, 23));
createJTable(p1);
p1.setVisible(false);
p2.setLayout(null);
p2.setBounds(0, 145, 800, 555);
p2.setBackground(new Color(233, 33, 00, 23));
createJTable1(p2);
p2.setVisible(false);
p3.setLayout(null);
p3.setBounds(0, 145, 800, 555);
p3.setBackground(new Color(233, 33, 00, 23));
createJTable2(p3);
p3.setVisible(false);
JButton bt1 = new JButton("在住客人");
JButton bt2 = new JButton("预定客人");
JButton bt3 = new JButton("历史客人");
JButton bt4 = new JButton("返回主界面");
ptop.setBounds(365, 20,120 , 20);
ptop.setFont(new Font("Arials", 0, 20));
p1top.setBounds(340, 0,120 , 20);
p1top.setFont(new Font("Arials", 0, 20));
p2top.setBounds(340, 0,120 , 20);
p2top.setFont(new Font("Arials", 0, 20));
p3top.setBounds(340, 0,120 , 20);
p3top.setFont(new Font("Arials", 0, 20));
bt1.setBounds(165, 70, 120, 40);
bt1.setFont(new Font("Arials", 0, 17));
bt1.setBackground(new Color(229, 241, 251));
bt1.addActionListener(new livinghandler());
bt2.setBounds(345, 70, 120, 40);
bt2.setFont(new Font("Arials", 0, 17));
bt2.setBackground(new Color(229, 241, 251));
bt2.addActionListener(new bookinghandler());
bt3.setBounds(525, 70, 120, 40);
bt3.setFont(new Font("Arials", 0, 17));
bt3.setBackground(new Color(229, 241, 251));
bt3.addActionListener(new leavehandler());
bt4.setBounds(525, 20, 120, 40);
bt4.setFont(new Font("Arials", 0, 17));
bt4.setBackground(new Color(229, 241, 251));
p.add(bt4);
p.add(bt3);
p.add(bt2);
p.add(bt1);
p.add(ptop);
p1.add(p1top);
p2.add(p2top);
p3.add(p3top);
con.add(p);
con.add(p1);
con.add(p2);
con.add(p3);
f.setLayout(null);
f.setLocationRelativeTo(null);
f.setVisible(true);
f.setSize(800, 500);
f.setResizable(false);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// f.setMaximizedBounds(null);
}
public void createJTable(JPanel jp ) {
JScrollPane jsp=new JScrollPane();
String[] columnNames = { "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "房号"};
Object[][] obj={
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "1"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "2"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "3"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "4"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "5"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "6"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "7"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "8"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "9"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "0"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "2"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "3"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "4"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "5"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "6"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "7"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "8"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "9"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "0"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "2"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "3"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "4"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "5"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "6"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "7"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "8"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "9"},
{ "证件号码", "姓名", "性别" ,"证件类型", "电话号码", "0"}
};
JTable table = new JTable(obj, columnNames);
table.setRowHeight(30);
table.getColumnModel().getColumn(0).setPreferredWidth(200);
table.getColumnModel().getColumn(1).setPreferredWidth(100);
table.getColumnModel().getColumn(2).setPreferredWidth(90);
table.getColumnModel().getColumn(3).setPreferredWidth(142);
table.getColumnModel().getColumn(4).setPreferredWidth(160);
table.getColumnModel().getColumn(5).setPreferredWidth(90);
table.setBounds(0,0,782, 200);
table.setEnabled(false);
table.setRequestFocusEnabled(false);
table.setRowSelectionAllowed(false);
table.setBackground(new Color(233, 33, 00, 23));
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setVisible(true);
table.setFont(new Font("Arials", 0, 16));
setTableColumnCenter(table);
table.getTableHeader().setEnabled(false);
table.getTableHeader().setReorderingAllowed(false);
table.getTableHeader().setResizingAllowed(false);
table.getTableHeader().setBackground(new Color(233, 33, 00, 23));
table.getTableHeader().setVisible(true);
table.getTableHeader().setEnabled(false);
table.getTableHeader().setReorderingAllowed(false);
table.getTableHeader().setResizingAllowed(false);
jsp.setBounds(0,40, 800, 200);
jsp.setVisible(true);
jsp.setBackground(new Color(233, 33, 00, 23));
jsp.getViewport().add(table);
jp.add(jsp);
}