日期:2014-05-20 浏览次数:20883 次
MyFrame(String s) { this.setTitle(s); this.setLayout(new BorderLayout()); this.setBounds(500, 100, 300, 455); JPanel p1 = new JPanel(new FlowLayout()); JPanel p3 = new JPanel(new GridLayout(3,1)); JLabel lb = new JLabel("索引 :"); lb.setFont(new Font("黑体",Font.BOLD ,15)); tf = new JTextField(18); p1.add(lb); p1.add(tf); this.add(p1,BorderLayout.NORTH); this.initialize(); ta = new JTable(model); ta.setRowSelectionInterval(0, 0); DefaultTableCellRenderer r = new DefaultTableCellRenderer(); r.setHorizontalAlignment(JLabel.CENTER); ta.setDefaultRenderer(Object.class, r); ta.setAutoCreateRowSorter(true); ta.setBackground(Color.PINK); sp = new JScrollPane(); sp.getViewport().add(ta); this.add(sp,BorderLayout.CENTER); JButton b1 = new JButton("增 加"); b1.setFont(new Font("华文行楷",Font.PLAIN,20)); JButton b2 = new JButton("删 除"); b2.setFont(new Font("华文行楷",Font.PLAIN,20)); JButton b3 = new JButton("修 改"); b3.setFont(new Font("华文行楷",Font.PLAIN,20)); p3.add(b1); p3.add(b2); p3.add(b3); this.add(p3,BorderLayout.SOUTH); b1.addMouseListener(new MouseListener()); b2.addMouseListener(new MouseListener2()); b3.addMouseListener(new MouseListener3()); this.addWindowListener(new windowMonitor()); ThreadMonitor t = new ThreadMonitor(); t.run(); this.setIconImage(img); this.validate(); this.setVisible(true); }
------解决方案--------------------
this.setVisible(true);
放构造方法最后一句试试