Example usage for javax.swing JTable setGridColor

List of usage examples for javax.swing JTable setGridColor

Introduction

In this page you can find the example usage for javax.swing JTable setGridColor.

Prototype

@BeanProperty(description = "The grid color.")
public void setGridColor(Color gridColor) 

Source Link

Document

Sets the color used to draw grid lines to gridColor and redisplays.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JTable table = new JTable();

    table.setGridColor(Color.red);

}

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  w w  .  j  a  v a 2s .co  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:gui.accessories.BattleSimFx.java

@Override
public void init() {
    tableModel = new SampleTableModel();
    // create javafx panel for charts
    chartFxPanel = new JFXPanel();
    chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT));

    //JTable/*from  w w  w. ja  v  a  2  s.co  m*/
    JTable table = new JTable(tableModel);
    table.setAutoCreateRowSorter(true);
    table.setGridColor(Color.DARK_GRAY);
    BattleSimFx.DecimalFormatRenderer renderer = new BattleSimFx.DecimalFormatRenderer();
    renderer.setHorizontalAlignment(JLabel.RIGHT);
    for (int i = 0; i < table.getColumnCount(); i++) {
        table.getColumnModel().getColumn(i).setCellRenderer(renderer);
    }
    JScrollPane tablePanel = new JScrollPane(table);
    tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT));

    JPanel chartTablePanel = new JPanel();
    chartTablePanel.setLayout(new BorderLayout());

    //Split pane that holds both chart and table
    JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    jsplitPane.setTopComponent(chartTablePanel);
    jsplitPane.setBottomComponent(tablePanel);
    jsplitPane.setDividerLocation(410);
    chartTablePanel.add(chartFxPanel, BorderLayout.CENTER);

    //          add(tablePanel, BorderLayout.CENTER);
    add(jsplitPane, BorderLayout.CENTER);

    // create JavaFX scene
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            createScene();
        }
    });
}

From source file:SampleTableModel.java

@Override
public void init() {
    tableModel = new SampleTableModel();
    // create javafx panel for charts
    chartFxPanel = new JFXPanel();
    chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT));

    //JTable// w w  w .  j  av  a  2  s  .  com
    JTable table = new JTable(tableModel);
    table.setAutoCreateRowSorter(true);
    table.setGridColor(Color.DARK_GRAY);
    SwingInterop.DecimalFormatRenderer renderer = new SwingInterop.DecimalFormatRenderer();
    renderer.setHorizontalAlignment(JLabel.RIGHT);
    for (int i = 0; i < table.getColumnCount(); i++) {
        table.getColumnModel().getColumn(i).setCellRenderer(renderer);
    }
    JScrollPane tablePanel = new JScrollPane(table);
    tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT));

    JPanel chartTablePanel = new JPanel();
    chartTablePanel.setLayout(new BorderLayout());

    //Split pane that holds both chart and table
    JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    jsplitPane.setTopComponent(chartTablePanel);
    jsplitPane.setBottomComponent(tablePanel);
    jsplitPane.setDividerLocation(410);
    chartTablePanel.add(chartFxPanel, BorderLayout.CENTER);

    //          add(tablePanel, BorderLayout.CENTER);
    add(jsplitPane, BorderLayout.CENTER);

    // create JavaFX scene
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            createScene();
        }
    });
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Show differences./*from   w  ww  .ja  va 2 s . c o m*/
 */
private void showDifferencesDialog(final Collection<SubjectiveScoreDifference> diffs) {
    final SubjectiveDiffTableModel model = new SubjectiveDiffTableModel(diffs);
    final JTable table = new JTable(model);
    table.setGridColor(Color.BLACK);

    table.addMouseListener(new MouseAdapter() {
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                final JTable target = (JTable) e.getSource();
                final int row = target.getSelectedRow();

                final SubjectiveScoreDifference diff = model.getDiffForRow(row);

                // find correct table
                final String category = diff.getCategory();
                final JTable scoreTable = getTableForTitle(category);
                final int tabIndex = getTabIndexForCategory(category);
                getTabbedPane().setSelectedIndex(tabIndex);

                // get correct row and column
                final SubjectiveTableModel model = (SubjectiveTableModel) scoreTable.getModel();
                final int scoreRow = model.getRowForTeamAndJudge(diff.getTeamNumber(), diff.getJudge());
                final int scoreCol = model.getColForSubcategory(diff.getSubcategory());
                if (scoreRow == -1 || scoreCol == -1) {
                    throw new FLLRuntimeException(
                            "Internal error: Cannot find correct row and column for score difference: " + diff);
                }

                scoreTable.changeSelection(scoreRow, scoreCol, false, false);
            }
        }
    });

    final JDialog dialog = new JDialog(this, false);
    final Container cpane = dialog.getContentPane();
    cpane.setLayout(new BorderLayout());
    final JScrollPane tableScroller = new JScrollPane(table);
    cpane.add(tableScroller, BorderLayout.CENTER);

    dialog.pack();
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setVisible(true);
}

From source file:fll.subjective.SubjectiveFrame.java

private void createSubjectiveTable(final JTabbedPane tabbedPane, final ScoreCategory subjectiveCategory) {
    final SubjectiveTableModel tableModel = new SubjectiveTableModel(_scoreDocument, subjectiveCategory,
            _schedule, _scheduleColumnMappings);
    final JTable table = new JTable(tableModel);
    table.setDefaultRenderer(Date.class, DateRenderer.INSTANCE);

    // Make grid lines black (needed for Mac)
    table.setGridColor(Color.BLACK);

    // auto table sorter
    table.setAutoCreateRowSorter(true);//from  w w  w  .ja  v  a2s  .  c om

    final String title = subjectiveCategory.getTitle();
    _tables.put(title, table);
    final JScrollPane tableScroller = new JScrollPane(table);
    tableScroller.setPreferredSize(new Dimension(640, 480));
    tabbedPane.addTab(title, tableScroller);

    table.setSelectionBackground(Color.YELLOW);

    setupTabReturnBehavior(table);

    int goalIndex = 0;
    for (final AbstractGoal goal : subjectiveCategory.getGoals()) {
        final TableColumn column = table.getColumnModel()
                .getColumn(goalIndex + tableModel.getNumColumnsLeftOfScores());
        if (goal.isEnumerated()) {
            final Vector<String> posValues = new Vector<String>();
            posValues.add("");
            for (final EnumeratedValue posValue : goal.getSortedValues()) {
                posValues.add(posValue.getTitle());
            }

            column.setCellEditor(new DefaultCellEditor(new JComboBox<String>(posValues)));
        } else {
            final JTextField editor = new SelectTextField();
            column.setCellEditor(new DefaultCellEditor(editor));
        }
        ++goalIndex;
    }
}

From source file:org.isatools.isacreator.gui.formelements.SubForm.java

protected void setTableProperties(JTable table, boolean isFieldName) {
    Font font = (!isFieldName) ? UIHelper.VER_12_PLAIN : UIHelper.VER_12_BOLD;
    table.setFont(font);//  w  w w  . j av  a2  s . c  o m
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);
    table.setGridColor(UIHelper.LIGHT_GREEN_COLOR);
    table.setShowGrid(true);
}

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

/**
 * Setup the JTable with its desired characteristics
 *//*from   w w  w  . j  a v a  2 s  . 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();
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.ChannelAcquisitionComponent.java

/**
 * Sets the plane info for the specified channel.
 * //  w w w  . j a  v a  2 s  .  c o  m
 * @param index  The index of the channel.
 */
void setPlaneInfo(int index) {
    if (channel.getIndex() != index)
        return;
    Collection result = model.getChannelPlaneInfo(index);
    String[][] values = new String[2][result.size() + 1];
    String[] names = new String[result.size() + 1];
    int i = 0;
    Iterator j = result.iterator();
    PlaneInfo info;
    Map<String, Object> details;
    List<String> notSet;
    names[0] = "t";
    values[0][i] = "Delta T";
    values[1][i] = "Exposure";
    i++;
    while (j.hasNext()) {
        info = (PlaneInfo) j.next();
        details = EditorUtil.transformPlaneInfo(info);
        notSet = (List<String>) details.get(EditorUtil.NOT_SET);
        if (!notSet.contains(EditorUtil.DELTA_T)) {
            if (details.get(EditorUtil.DELTA_T) instanceof BigResult) {
                MetadataViewerAgent.logBigResultExeption(this, details.get(EditorUtil.DELTA_T),
                        EditorUtil.DELTA_T);
                values[0][i] = "N/A";
            } else {
                double tInS = ((Double) details.get(EditorUtil.DELTA_T));
                values[0][i] = getReadableTime(tInS);
            }
        } else
            values[0][i] = "--";

        if (!notSet.contains(EditorUtil.EXPOSURE_TIME)) {
            if (details.get(EditorUtil.EXPOSURE_TIME) instanceof BigResult) {
                MetadataViewerAgent.logBigResultExeption(this, details.get(EditorUtil.EXPOSURE_TIME),
                        EditorUtil.EXPOSURE_TIME);
                values[1][i] = "N/A";
            } else {
                double tInS = ((Double) details.get(EditorUtil.EXPOSURE_TIME));
                values[1][i] = getReadableTime(tInS);
            }
        } else
            values[1][i] = "--";
        names[i] = "t=" + i;
        i++;
    }
    if (i > 1) {
        JTable table = new JTable(values, names);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setShowGrid(true);
        table.setGridColor(Color.LIGHT_GRAY);
        JScrollPane pane = new JScrollPane(table);
        Dimension d = table.getPreferredSize();
        Dimension de = exposureTask.getPreferredSize();
        pane.setPreferredSize(new Dimension(de.width - 10, 4 * d.height));
        exposureTask.add(pane);
        exposureTask.setVisible(true);
    } else {
        exposureTask.setVisible(false);
    }
}

From source file:org.rivalry.swingui.SortTablePanel.java

/**
 * @param tableModel Table model./*w  w w.  j ava  2  s .  c o m*/
 *
 * @return a new table.
 */
private JTable createTable(final TableModel tableModel) {
    final JTable answer = new ColumnNameToolTipTable(tableModel);

    answer.setAutoCreateRowSorter(true);
    answer.setGridColor(Color.GRAY);

    final RowSorter<? extends TableModel> rowSorter = answer.getRowSorter();
    rowSorter.addRowSorterListener(new RowSorterListener() {
        @Override
        public void sorterChanged(final RowSorterEvent event) {
            final List<? extends SortKey> sortKeys = rowSorter.getSortKeys();

            if (CollectionUtils.isNotEmpty(sortKeys)) {
                _userPreferences.putSortKey(sortKeys.get(0));
            }
        }
    });

    return answer;
}