发布网友 发布时间:2022-06-03 05:49
共1个回答
热心网友 时间:2023-10-12 18:23
import java.awt.*;追问表格 我说错了 多弄几列行吗
追答import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JTableDemo extends JFrame {
privateJPanel topPanel;
privateJTable table;
public JTableDemo(){
setTitle( "Simple JTable Application" );
setSize( 300, 100 );
setBackground( Color.gray );
topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
String cols[] = {
"Col 1",
"Col 2",
"Col 3"
};
String rowData[][] = {
{ "Row1-Column1", "Row1-Column2", "Row1-Column3"},
{ "Row2-Column1", "Row2-Column2", "Row2-Column3"}
};
table = new JTable(rowData, cols);
JScrollPane scrollPane = new JScrollPane(table);
topPanel.add( scrollPane, BorderLayout.CENTER );
}
public static void main( String args[] ) {
JTableDemo mainFrame = new JTableDemo();
mainFrame.setVisible( true );
}
}