Java图形界面用Jtable显示不出来,已经加在JScrollPane了
2019-06-11
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
public class TestWin extends JFrame implements ActionListener {
private JTextField nameField = new JTextField(12);
private JButton queryBtn = new JButton("查询");
private JTable table = new JTable(new Object[][] {}, new String[] { "姓名", "学号", "班级" });
public TestWin() {
queryBtn.addActionListener(this);
JLabel label = new JLabel("查询信息");
label.setFont(new Font("宋体",Font.BOLD,24));
JLabel nameLabel = new JLabel("学生姓名:");
JPanel northPane = new JPanel();
BoxLayout layout = new BoxLayout(northPane, BoxLayout.Y_AXIS);
northPane.setLayout(layout);
Box box = Box.createHorizontalBox();
box.setBorder(new EmptyBorder(20,10,10,10));
box.add(label);
northPane.add(box);
box = Box.createHorizontalBox();
box.setBorder(new EmptyBorder(10,10,10,10));
box.add(nameLabel);
box.add(nameField);
box.add(queryBtn);
northPane.add(box);
add(northPane, "North");
add(new JScrollPane(table), "Center");
setSize(400, 300);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new TestWin().setVisible(true));
}
}
还是不行