我知道,如何在Scrollpane裏面添加表格。但我已經介紹了一個循環,這是創建問題,所以請幫助我擺脫這個問題(我想添加滾動窗格內的表),似乎它的工作,只要我不介紹scrollpane,但每當我把表內的scrollpane,它不起作用。請幫忙。如何在jscrollpane內添加jtable?
在此先感謝。
這裏是我的代碼:
import javax.swing.DefaultCellEditor;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import java.awt.*;
import javax.swing.*;
public class Simple
{
JScrollPane mainScroll;
JPanel panel;
JFrame frame;
public Simple()
{
frame=new JFrame();
panel=new JPanel();
mainScroll=new JScrollPane();
Object[][] rowData = {};
Object[] columnNames = { "Sr.No","Subject","Department","Status" };
JComboBox mainBox=new JComboBox();
mainBox.addItem("Processed");
mainBox.addItem("Pending");
DefaultTableModel listTableModel;
listTableModel = new DefaultTableModel(rowData, columnNames);
for (int i = 0; i < 1000; i++) {
String main = "" + i;
listTableModel.addRow(new Object[] { main, "", "" ,"Choose"});
JTable listTable;
listTable = new JTable(listTableModel);
TableColumn StatusColumn=listTable.getColumnModel().getColumn(3);
StatusColumn.setCellEditor(new DefaultCellEditor(mainBox));
mainScroll.add(listTable);
}
panel.setLayout(null);
mainScroll.setBounds(37, 143, 397, 183);
// mainBox.addItem("Processing");
frame.add(panel);
panel.add(mainScroll);
frame.setSize(600,600);
frame.setVisible(true);
}
public static void main(String arg[])
{
new Simple();
}
}
您想添加滾動窗格內千個表? – Lars
1000行不是表 – kartik