List of usage examples for javax.swing JTable setShowHorizontalLines
@BeanProperty(description = "Whether horizontal lines should be drawn in between the cells.") public void setShowHorizontalLines(boolean showHorizontalLines)
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); table.setShowGrid(false);/* w ww . jav a2 s . co m*/ table.setShowHorizontalLines(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); table.setShowGrid(false);//Don't show any grid lines //Show only vertical grid lines table.setShowGrid(false);/* w ww . j av a 2s .c o m*/ table.setShowVerticalLines(true); //Show only horizontal grid lines table.setShowGrid(false); table.setShowHorizontalLines(true); //Set the grid color table.setGridColor(Color.red); //Show both horizontal and vertical grid lines (the default) table.setShowGrid(true); }
From source file:DefaultsDisplay.java
protected JTable createDefaultsTable() { JTable table = new JTable(new UIDefaultsTableModel()); table.setRowHeight(rowHeight);//from w ww .j a va 2 s .co m table.setShowHorizontalLines(false); table.setShowVerticalLines(false); table.setIntercellSpacing(new Dimension(0, 0)); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); initFilters(table); DefaultTableColumnModel columnModel = new DefaultTableColumnModel(); Color rowColors[] = new Color[2]; rowColors[0] = UIManager.getColor("Table.background"); rowColors[1] = new Color((int) (rowColors[0].getRed() * .90), (int) (rowColors[0].getGreen() * .95), (int) (rowColors[0].getBlue() * .95)); int width = 0; TableColumn column = new TableColumn(); column.setCellRenderer(new KeyRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.KEY_COLUMN); column.setHeaderValue("Key"); column.setPreferredWidth(250); columnModel.addColumn(column); width += column.getPreferredWidth(); column = new TableColumn(); column.setCellRenderer(new RowRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.TYPE_COLUMN); column.setHeaderValue("Type"); column.setPreferredWidth(250); columnModel.addColumn(column); width += column.getPreferredWidth(); column = new TableColumn(); column.setCellRenderer(new ValueRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.VALUE_COLUMN); column.setHeaderValue("Value"); column.setPreferredWidth(300); columnModel.addColumn(column); width += column.getPreferredWidth(); table.setColumnModel(columnModel); table.setPreferredScrollableViewportSize(new Dimension(width, 12 * rowHeight)); return table; }
From source file:Visuals.BarChart.java
public JPanel addCharts() { ChartPanel barPanel = drawBarChart(); barPanel.setDomainZoomable(true);//from w w w . j ava2 s .c o m JPanel thisBarPanel = new JPanel(); thisBarPanel.setLayout(new BorderLayout()); String[][] finalRisks = new String[riskCount][4]; for (int i = 0; i < riskCount; i++) { finalRisks[i][0] = risks[i][0]; finalRisks[i][1] = risks[i][1]; finalRisks[i][2] = risks[i][2]; finalRisks[i][3] = risks[i][3]; } JTable table = new JTable(finalRisks, columns); //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel()); table.setRowSorter(sorter); List<RowSorter.SortKey> sortKeys = new ArrayList<>(); int columnIndexToSort = 2; sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); TableColumn tcol = table.getColumnModel().getColumn(2); table.removeColumn(tcol); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getColumnModel().getColumn(1).setPreferredWidth(600); table.getColumnModel().getColumn(2).setPreferredWidth(600); table.setShowHorizontalLines(true); table.setRowHeight(40); table.setEnabled(false); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = table.getPreferredSize(); tableScrollPane .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1))); JLabel right = new JLabel( " "); thisBarPanel.add(right, BorderLayout.EAST); thisBarPanel.add(barPanel, BorderLayout.CENTER); thisBarPanel.add(tableScrollPane, BorderLayout.SOUTH); return thisBarPanel; }
From source file:UI.SecurityDashboard.java
private void performMetric9() { GZDecompression m9 = new GZDecompression(); String[][] counts = m9.getMetric9(); Font titleFont = new Font("Calibri", Font.BOLD, 27); JLabel logAuditTitleLabel = new JLabel(" Log Audit"); logAuditTitleLabel.setFont(titleFont); AreaChart areaChart = new AreaChart(m9.getLogCount(), m9.getSuccessCount(), m9.getFailCount()); ChartPanel thisChart = areaChart.drawAreaChart(); thisChart.setBackground(Color.white); thisChart.addChartMouseListener(new ChartMouseListener() { @Override//w w w. jav a2 s . c o m public void chartMouseClicked(ChartMouseEvent cme) { dashboardTabs.setSelectedIndex(9); } @Override public void chartMouseMoved(ChartMouseEvent cme) { } }); Metric9Panel.setBackground(Color.WHITE); Metric9Panel.setLayout(new BorderLayout()); Metric9Panel.add(logAuditTitleLabel, BorderLayout.NORTH); Metric9Panel.add(thisChart, BorderLayout.CENTER); Metric9Panel.setEnabled(false); String[] columns = { "Log Failure" }; JTable table = new JTable(counts, columns); table.setShowHorizontalLines(true); table.setRowHeight(40); table.setEnabled(false); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); AuditPanel.setLayout(new BorderLayout()); JTextArea header = new JTextArea( "\nThrough the analysis of security logs, this page will show an audit of the attack attempts and " + "security breaches. The logs provide critical information related to system events that can be used to track suspicicous " + "activities.\n"); header.setLineWrap(true); header.setWrapStyleWord(true); header.setEditable(false); AuditPanel.add(header, BorderLayout.NORTH); AuditPanel.add(tableScrollPane, BorderLayout.CENTER); }
From source file:Visuals.PieChart.java
public JPanel addCharts() { ChartPanel piePanel = drawPieChart(); piePanel.setDomainZoomable(true);//from w ww .j a v a 2s. c o m JPanel thisPiePanel = new JPanel(); String[][] finalRisks = new String[riskCount][4]; for (int i = 0; i < riskCount; i++) { finalRisks[i][0] = risks[i][0]; finalRisks[i][1] = risks[i][1]; finalRisks[i][2] = risks[i][2]; finalRisks[i][3] = risks[i][3]; } JTable table = new JTable(finalRisks, columns); //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel()); table.setRowSorter(sorter); List<RowSorter.SortKey> sortKeys = new ArrayList<>(); int columnIndexToSort = 2; sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); TableColumn tcol = table.getColumnModel().getColumn(2); table.removeColumn(tcol); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getColumnModel().getColumn(1).setPreferredWidth(600); table.getColumnModel().getColumn(2).setPreferredWidth(600); JLabel right = new JLabel( " "); thisPiePanel.add(right, BorderLayout.EAST); table.setShowHorizontalLines(true); table.setRowHeight(40); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = table.getPreferredSize(); tableScrollPane .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1))); table.setEnabled(false); thisPiePanel.setLayout(new BorderLayout()); if (riskCount == 0) { thisPiePanel.add(piePanel, BorderLayout.CENTER); } else { thisPiePanel.add(right, BorderLayout.EAST); thisPiePanel.add(piePanel, BorderLayout.CENTER); thisPiePanel.add(tableScrollPane, BorderLayout.SOUTH); } thisPiePanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); return thisPiePanel; }
From source file:Visuals.RingChart.java
public JPanel addDefenceCharts() { lowValue = "Low (" + low + ")"; ChartPanel ringPanel = drawRingChart(); ringPanel.setDomainZoomable(true);//from ww w. jav a 2s. c om JPanel thisRingPanel = new JPanel(); thisRingPanel.setLayout(new BorderLayout()); String[][] finalRisks = new String[riskCount][4]; for (int i = 0; i < riskCount; i++) { finalRisks[i][0] = risks[i][0]; finalRisks[i][1] = risks[i][1]; finalRisks[i][2] = risks[i][2]; finalRisks[i][3] = risks[i][3]; } JTable table = new JTable(finalRisks, networkDefenceColumns); TableColumn tcol = table.getColumnModel().getColumn(2); table.removeColumn(tcol); table.setEnabled(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); int width = 0; for (int row = 0; row < table.getRowCount(); row++) { TableCellRenderer renderer = table.getCellRenderer(row, 1); Component comp = table.prepareRenderer(renderer, row, 1); width = Math.max(comp.getPreferredSize().width, width); } table.getColumnModel().getColumn(1).setPreferredWidth(width); width = 0; for (int row = 0; row < table.getRowCount(); row++) { TableCellRenderer renderer = table.getCellRenderer(row, 2); Component comp = table.prepareRenderer(renderer, row, 2); width = Math.max(comp.getPreferredSize().width, width); } table.getColumnModel().getColumn(2).setPreferredWidth(width); table.setShowHorizontalLines(true); table.setRowHeight(40); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = table.getPreferredSize(); tableScrollPane .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1))); JLabel right = new JLabel( " "); thisRingPanel.add(right, BorderLayout.EAST); thisRingPanel.add(ringPanel, BorderLayout.CENTER); thisRingPanel.add(tableScrollPane, BorderLayout.SOUTH); return thisRingPanel; }
From source file:Visuals.RingChart.java
public JPanel addAVCharts() { JPanel thisPanel = new JPanel(); thisPanel.setLayout(new BorderLayout()); int tempCriticalCount = 0, tempUpdatedCount = 0; String[][] criticalList = new String[critical][4]; String[][] updatedList = new String[low][4]; for (int i = 0; i < riskCount; i++) { if (risks[i][2].equals("Critical")) { criticalList[tempCriticalCount][0] = risks[i][0]; criticalList[tempCriticalCount][1] = risks[i][1]; criticalList[tempCriticalCount][3] = risks[i][3]; tempCriticalCount++;//from w w w. ja va2 s . co m } if (risks[i][2].equals("Low")) { updatedList[tempUpdatedCount][0] = risks[i][0]; updatedList[tempUpdatedCount][1] = risks[i][1]; tempUpdatedCount++; } } JTable criticalTable = new JTable(criticalList, criticalColumns); JTable updatedTable = new JTable(updatedList, updatedColumns); TableColumn tcol = criticalTable.getColumnModel().getColumn(2); criticalTable.removeColumn(tcol); TableColumn tcol2 = updatedTable.getColumnModel().getColumn(2); updatedTable.removeColumn(tcol2); criticalTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); updatedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); criticalTable.setEnabled(false); updatedTable.setEnabled(false); int width = 0; for (int i = 0; i < 3; i++) { for (int row = 0; row < criticalTable.getRowCount(); row++) { TableCellRenderer renderer = criticalTable.getCellRenderer(row, i); Component comp = criticalTable.prepareRenderer(renderer, row, i); width = Math.max(comp.getPreferredSize().width, width); } criticalTable.getColumnModel().getColumn(i).setPreferredWidth(width); width = 0; } for (int i = 0; i < 2; i++) { for (int row = 0; row < updatedTable.getRowCount(); row++) { TableCellRenderer renderer = updatedTable.getCellRenderer(row, i); Component comp = updatedTable.prepareRenderer(renderer, row, i); width = Math.max(comp.getPreferredSize().width, width); } updatedTable.getColumnModel().getColumn(i).setPreferredWidth(width); width = 0; } criticalTable.setShowHorizontalLines(true); criticalTable.setRowHeight(40); updatedTable.setShowHorizontalLines(true); updatedTable.setRowHeight(40); JScrollPane criticalTableScrollPane = new JScrollPane(criticalTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); JScrollPane updatedTableScrollPane = new JScrollPane(updatedTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = criticalTable.getPreferredSize(); criticalTableScrollPane.setPreferredSize( new Dimension((d.width - 400), (criticalTable.getRowHeight() + 1) * (tempCriticalCount + 1))); Dimension d2 = updatedTable.getPreferredSize(); updatedTableScrollPane.setPreferredSize( new Dimension((d.width - 400), (updatedTable.getRowHeight() + 1) * (tempUpdatedCount + 1))); Font titleFonts = new Font("Calibri", Font.BOLD, 30); JLabel criticalLabel = new JLabel(" Critical "); criticalLabel.setFont(titleFonts); criticalLabel.setForeground(new Color(230, 27, 27)); JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BorderLayout()); leftPanel.add(criticalLabel, BorderLayout.WEST); leftPanel.add(criticalTableScrollPane, BorderLayout.CENTER); JLabel updatedLabel = new JLabel(" Updated "); updatedLabel.setFont(titleFonts); updatedLabel.setForeground(new Color(47, 196, 6)); JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BorderLayout()); rightPanel.add(updatedLabel, BorderLayout.WEST); rightPanel.add(updatedTableScrollPane, BorderLayout.CENTER); if (tempCriticalCount != 0) thisPanel.add(leftPanel, BorderLayout.NORTH); if (tempUpdatedCount != 0) thisPanel.add(rightPanel, BorderLayout.SOUTH); return thisPanel; }
From source file:org.formic.wizard.step.gui.FeatureListStep.java
/** * {@inheritDoc}/* w w w .java 2s .c om*/ * @see org.formic.wizard.step.GuiStep#init() */ public Component init() { featureInfo = new JEditorPane("text/html", StringUtils.EMPTY); featureInfo.setEditable(false); featureInfo.addHyperlinkListener(new HyperlinkListener()); Feature[] features = provider.getFeatures(); JTable table = new JTable(features.length, 1) { private static final long serialVersionUID = 1L; public Class getColumnClass(int column) { return getValueAt(0, column).getClass(); } public boolean isCellEditable(int row, int column) { return false; } }; table.setBackground(new javax.swing.JList().getBackground()); GuiForm form = createForm(); for (int ii = 0; ii < features.length; ii++) { final Feature feature = (Feature) features[ii]; final JCheckBox box = new JCheckBox(); String name = getName() + '.' + feature.getKey(); form.bind(name, box); box.putClientProperty("feature", feature); featureMap.put(feature.getKey(), box); if (feature.getInfo() == null) { feature.setInfo(Installer.getString(getName() + "." + feature.getKey() + ".html")); } feature.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (Feature.ENABLED_PROPERTY.equals(event.getPropertyName())) { if (box.isSelected() != feature.isEnabled()) { box.setSelected(feature.isEnabled()); } } } }); box.setText(Installer.getString(name)); box.setBackground(table.getBackground()); if (!feature.isAvailable()) { box.setSelected(false); box.setEnabled(false); } table.setValueAt(box, ii, 0); } FeatureListMouseListener mouseListener = new FeatureListMouseListener(); for (int ii = 0; ii < features.length; ii++) { Feature feature = (Feature) features[ii]; if (feature.isEnabled() && feature.isAvailable()) { JCheckBox box = (JCheckBox) featureMap.get(feature.getKey()); box.setSelected(true); mouseListener.processDependencies(feature); mouseListener.processExclusives(feature); } } table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setShowHorizontalLines(false); table.setShowVerticalLines(false); table.setDefaultRenderer(JCheckBox.class, new ComponentTableCellRenderer()); table.addKeyListener(new FeatureListKeyListener()); table.addMouseListener(mouseListener); table.getSelectionModel().addListSelectionListener(new FeatureListSelectionListener(table)); table.setRowSelectionInterval(0, 0); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JPanel container = new JPanel(new BorderLayout()); container.add(table, BorderLayout.CENTER); panel.add(new JScrollPane(container), BorderLayout.CENTER); JScrollPane infoScroll = new JScrollPane(featureInfo); infoScroll.setMinimumSize(new Dimension(0, 50)); infoScroll.setMaximumSize(new Dimension(0, 50)); infoScroll.setPreferredSize(new Dimension(0, 50)); panel.add(infoScroll, BorderLayout.SOUTH); return panel; }
From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java
/** * Setup the JTable with its desired characteristics *//*from w ww . j a v a2s. c o m*/ private void setupTable() { table = new CustomTable(spreadsheetModel); table.setShowGrid(true); table.setGridColor(Color.BLACK); table.setShowVerticalLines(true); table.setShowHorizontalLines(true); table.setGridColor(UIHelper.LIGHT_GREEN_COLOR); table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(true); table.setAutoCreateColumnsFromModel(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getSelectionModel().addListSelectionListener(this); table.getColumnModel().getSelectionModel().addListSelectionListener(this); table.getTableHeader().setReorderingAllowed(true); table.getColumnModel().addColumnModelListener(this); try { table.setDefaultRenderer(Class.forName("java.lang.Object"), new SpreadsheetCellRenderer()); } catch (ClassNotFoundException e) { // ignore this error } table.addMouseListener(this); table.getTableHeader().addMouseMotionListener(new MouseMotionListener() { public void mouseDragged(MouseEvent event) { } public void mouseMoved(MouseEvent event) { // display a tooltip when user hovers over a column. tooltip is derived // from the description of a field from the TableReferenceObject. JTable table = ((JTableHeader) event.getSource()).getTable(); TableColumnModel colModel = table.getColumnModel(); int colIndex = colModel.getColumnIndexAtX(event.getX()); // greater than 1 to account for the row no. being the first col if (colIndex >= 1) { TableColumn tc = colModel.getColumn(colIndex); if (tc != null) { try { table.getTableHeader().setToolTipText(getFieldDescription(tc)); } catch (Exception e) { // ignore this error } } } } }); //table.getColumnModel().addColumnModelListener(this); InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); // Override the default tab behaviour // Tab to the next editable cell. When no editable cells goto next cell. final Action previousTabAction = table.getActionMap().get(im.get(tab)); Action newTabAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { // maintain previous tab action procedure previousTabAction.actionPerformed(e); JTable table = (JTable) e.getSource(); int row = table.getSelectedRow(); int originalRow = row; int column = table.getSelectedColumn(); int originalColumn = column; while (!table.isCellEditable(row, column)) { previousTabAction.actionPerformed(e); row = table.getSelectedRow(); column = table.getSelectedColumn(); // Back to where we started, get out. if ((row == originalRow) && (column == originalColumn)) { break; } } if (table.editCellAt(row, column)) { table.getEditorComponent().requestFocusInWindow(); } } }; table.getActionMap().put(im.get(tab), newTabAction); TableColumnModel model = table.getColumnModel(); String previousColumnName = null; for (int columnIndex = 0; columnIndex < tableReferenceObject.getHeaders().size(); columnIndex++) { if (!model.getColumn(columnIndex).getHeaderValue().toString() .equals(TableReferenceObject.ROW_NO_TEXT)) { model.getColumn(columnIndex).setHeaderRenderer(columnRenderer); model.getColumn(columnIndex).setPreferredWidth(spreadsheetFunctions .calcColWidths(model.getColumn(columnIndex).getHeaderValue().toString())); // add appropriate cell editor for cell. spreadsheetFunctions.addCellEditor(model.getColumn(columnIndex), previousColumnName); previousColumnName = model.getColumn(columnIndex).getHeaderValue().toString(); } else { model.getColumn(columnIndex).setHeaderRenderer(new RowNumberCellRenderer()); } } JTableHeader header = table.getTableHeader(); header.setBackground(UIHelper.BG_COLOR); header.addMouseListener(new HeaderListener(header, columnRenderer)); table.addNotify(); }