java表格不显示
packagecom.ccit.class167.gui;importjava.awt.Color;importjavax.swing.JFrame;importjava...
package com.ccit.class167.gui;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class MainFrame extends JFrame {
JPanel jPanel = null;
JScrollPane scrollPane = null;
JTable table = null;
JFrame frame = new JFrame();
Object datasObjects [][] = { { "1001", "张三", "30", "男" },
{ "1002", "李武", "26", "女" }, { "1003", "老王", "28", "男" },
{ "1004", "小三", "27", "女" } };
String fieldStrings[] = { "序号", "姓名", "年龄", "性别" };
public MainFrame() {
table = new JTable(new DefaultTableModel(datasObjects, fieldStrings));
table.selectAll();
table.setBackground(Color.WHITE);
table.setShowHorizontalLines(true);
table.setShowGrid(true);
table.setShowVerticalLines(true);
table.setSelectionBackground(Color.RED);
table.setSelectionForeground(Color.BLACK);
scrollPane = new JScrollPane();
scrollPane.add(table);
jPanel = new JPanel();
jPanel.setBounds(100, 100, 700, 500);
jPanel.setBackground(Color.LIGHT_GRAY);
jPanel.setForeground(Color.WHITE);
// jPanel.setName("表格");
jPanel.add(scrollPane);
frame.add(jPanel);
frame.setTitle("主界面");
frame.setBounds(200, 200, 1200, 800);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args) {
new MainFrame();
}
} 展开
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class MainFrame extends JFrame {
JPanel jPanel = null;
JScrollPane scrollPane = null;
JTable table = null;
JFrame frame = new JFrame();
Object datasObjects [][] = { { "1001", "张三", "30", "男" },
{ "1002", "李武", "26", "女" }, { "1003", "老王", "28", "男" },
{ "1004", "小三", "27", "女" } };
String fieldStrings[] = { "序号", "姓名", "年龄", "性别" };
public MainFrame() {
table = new JTable(new DefaultTableModel(datasObjects, fieldStrings));
table.selectAll();
table.setBackground(Color.WHITE);
table.setShowHorizontalLines(true);
table.setShowGrid(true);
table.setShowVerticalLines(true);
table.setSelectionBackground(Color.RED);
table.setSelectionForeground(Color.BLACK);
scrollPane = new JScrollPane();
scrollPane.add(table);
jPanel = new JPanel();
jPanel.setBounds(100, 100, 700, 500);
jPanel.setBackground(Color.LIGHT_GRAY);
jPanel.setForeground(Color.WHITE);
// jPanel.setName("表格");
jPanel.add(scrollPane);
frame.add(jPanel);
frame.setTitle("主界面");
frame.setBounds(200, 200, 1200, 800);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args) {
new MainFrame();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询