如何在 jscrollpane 中设置表格以及如何显示表格 header
How to set tabel in scrollpane and how to show tabel header
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 header 不显示。如何设置 table.I 的大小已使用 Google 但代码无法工作
要显示 table header,您应该在面板或框架中添加 JScrollPane
而不是 table
所以你应该这样做:
add(new JScrollPane(table));
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 header 不显示。如何设置 table.I 的大小已使用 Google 但代码无法工作
要显示 table header,您应该在面板或框架中添加 JScrollPane
而不是 table
所以你应该这样做:
add(new JScrollPane(table));