Java 程序在 JTable 中显示水平和垂直网格线
若要在表格中显示水平和垂直网格线,请使用 setShowGrid() 方法并将其设置为 true −
table.setShowGrid(true);
以下是一个在 JTable 中显示水平和垂直网格线的示例 −
示例
package my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class SwingDemo { public static void main(String[] argv) throws Exception { Integer[][] marks = { { 70, 66, 76, 89, 67, 98 }, { 67, 89, 64, 78, 59, 78 }, { 68, 87, 71, 65, 87, 86 }, { 80, 56, 89, 98, 59, 56 }, { 75, 95, 90, 73, 57, 79 }, { 69, 49, 56, 78, 76, 77 } }; String students[] = { "S1", "S2", "S3", "S4", "S5", "S6"}; JTable table = new JTable(marks, students); Font font = new Font("Verdana", Font.PLAIN, 12); table.setFont(font); table.setRowHeight(30); table.setGridColor(Color.yellow); table.setShowGrid(true); JFrame frame = new JFrame(); frame.setSize(600, 400); frame.add(new JScrollPane(table)); frame.setVisible(true); } }
输
广告