import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class StatusPage extends JPanel
{
DefaultTableModel dm;
JTable table;
JScrollPane jsb;
public StatusPage()
{
String col_name[] = {"S.No.","Book Name","Author Name","Available Book","Issue Book","Total Book"};
String data[][] = {{"1","Vikash","All","A","All","A"},{"1","Vikash","All","A","All","A"},{"1","Vikash","All","A","All","A"},{"1","Vikash","All","A","All","A"},{"1","Vikash","All","A","All","A"},{"1","Vikash","All","A","All","A"},{"1","Vikash","All","A","All","A"}};
dm = new DefaultTableModel(data,col_name);
table = new JTable(dm);
jsb = new JScrollPane(table);
add(table);
}
}
请检查错误。表头不显示。如何设置table的大小。我使用Google但代码无法正常工作
答案 0 :(得分:3)
要显示表格标题,您应在面板或框架中添加JScrollPane
而不是table
所以你应该这样做:
add(new JScrollPane(table));