下面列出了javax.swing.JTable#setGridColor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void setupTable(JTable table, int selectionModel, TableModel model, MouseListener mouseListener,
int... colWidth) {
table.setFillsViewportHeight(true);
table.setFont(StyleConstants.FONT_MONOSPACE_LARGE);
table.setRowHeight(StyleConstants.TABLE_ROW_HEIGHT_DEFAULT);
table.setShowHorizontalLines(true);
table.setShowVerticalLines(false);
table.setGridColor(Color.lightGray);
table.getColumnModel().setColumnMargin(StyleConstants.TABLE_COLUMN_MARGIN_DEFAULT);
table.setRowMargin(StyleConstants.TABLE_ROW_MARGIN_DEFAULT);
table.setSelectionMode(selectionModel);
if (model != null) {
table.setModel(model);
} else {
table.setModel(new DefaultTableModel());
}
if (mouseListener != null) {
table.removeMouseListener(mouseListener);
table.addMouseListener(mouseListener);
}
for (int i = 0; i < colWidth.length; i++) {
table.getColumnModel().getColumn(i).setMinWidth(colWidth[i]);
table.getColumnModel().getColumn(i).setMaxWidth(colWidth[i]);
}
}
@Override
protected void initComponents() {
final AbstractButton switchToChartButton = ToolButtonFactory.createButton(iconForSwitchToChartButton, false);
switchToChartButton.setToolTipText("Switch to Chart View");
switchToChartButton.setName("switchToChartButton");
switchToChartButton.setEnabled(hasAlternativeView());
switchToChartButton.addActionListener(e -> showAlternativeView());
final JPanel buttonPanel = new JPanel(new BorderLayout());
buttonPanel.add(switchToChartButton, BorderLayout.NORTH);
buttonPanel.add(getHelpButton(), BorderLayout.SOUTH);
add(buttonPanel, BorderLayout.EAST);
table = new JTable();
table.removeEditor();
table.setGridColor(Color.LIGHT_GRAY.brighter());
table.addMouseListener(new PagePanel.PopupHandler());
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
final JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
}
private static void checkTableGridLines() {
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() {
return 10;
}
public int getRowCount() {
return 10;
}
public Object getValueAt(int row, int col) {
return " ";
}
};
DefaultTableCellRenderer r = new DefaultTableCellRenderer();
r.setOpaque(true);
r.setBackground(CELL_RENDERER_BACKGROUND_COLOR);
JTable table = new JTable(dataModel);
table.setSize(WIDTH, HEIGHT);
table.setDefaultRenderer(Object.class, r);
table.setGridColor(GRID_COLOR);
table.setShowGrid(true);
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
table.setBackground(TABLE_BACKGROUND_COLOR);
checkTableGridLines(table);
}
private static void checkTableGridLines() {
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() {
return 10;
}
public int getRowCount() {
return 10;
}
public Object getValueAt(int row, int col) {
return " ";
}
};
DefaultTableCellRenderer r = new DefaultTableCellRenderer();
r.setOpaque(true);
r.setBackground(CELL_RENDERER_BACKGROUND_COLOR);
JTable table = new JTable(dataModel);
table.setSize(WIDTH, HEIGHT);
table.setDefaultRenderer(Object.class, r);
table.setGridColor(GRID_COLOR);
table.setShowGrid(true);
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
table.setBackground(TABLE_BACKGROUND_COLOR);
checkTableGridLines(table);
}