概述
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PrinterException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class Main {
public static void main(String args[]) {
final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" },
{ "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" },
{ "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" },
{ "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" },
{ "four", "4" },
};
final Object headers[] = { "English", "#" };
JFrame frame = new JFrame("Table Printing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTable table = new JTable(rows, headers);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane, BorderLayout.CENTER);
JButton button = new JButton("Print");
ActionListener printAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
table.print();
} catch (PrinterException pe) {
System.err.println("Error printing: " + pe.getMessage());
}
}
};
button.addActionListener(printAction);
frame.add(button, BorderLayout.SOUTH);
frame.setSize(300, 150);
frame.setVisible(true);
}
}
最后
以上就是俊逸手机为你收集整理的java jtable 内容_Java Swing - 如何更改JTable上的单元格内容...的全部内容,希望文章能够帮你解决java jtable 内容_Java Swing - 如何更改JTable上的单元格内容...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复