Java Code Examples for javax.swing.JTable#isRowSelected()

The following examples show how to use javax.swing.JTable#isRowSelected() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComboBoxTableCellEditor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected Component getEditorComponent (JTable  table,
                                        Object  value,
                                        boolean selected,
                                        int     row,
                                        int     col)
{

    setSelectedItem (value);

    //new or old row?
    selected = table.isRowSelected (row);
    if  (selected)  //old row
    {
        SwingUtilities.invokeLater (this.comboBoxFocusRequester);
        SwingUtilities.invokeLater (this.comboBoxOpener);
        return getComboBox ();
    }

    //the user selected a new row
    this.editor.removeAll ();  //remove the combobox from the panel

    return this.editor;

}
 
Example 2
Source File: EquipInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static List<EquipNode> getMenuTargets(JTable table, MouseEvent e)
{
	int row = table.rowAtPoint(e.getPoint());
	if (!table.isRowSelected(row))
	{
		if ((row >= 0) && (table.getRowCount() > row))
		{
			table.setRowSelectionInterval(row, row);
		}
	}
	return Arrays.stream(table.getSelectedRows())
	             .mapToObj(selRow -> table.getModel().getValueAt(selRow, 0))
	             .filter(value -> value instanceof EquipNode)
	             .map(value -> (EquipNode) value)
	             .collect(Collectors.toList());
}
 
Example 3
Source File: PurchaseInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static List<EquipmentFacade> getMenuTargets(JTable table, MouseEvent e)
{
	int row = table.rowAtPoint(e.getPoint());
	if (!table.isRowSelected(row))
	{
		if ((row >= 0) && (table.getRowCount() > row))
		{
			table.setRowSelectionInterval(row, row);
		}
	}
	return Arrays.stream(table.getSelectedRows())
	             .mapToObj(selRow -> table.getModel().getValueAt(selRow, 0))
	             .filter(value -> value instanceof EquipmentFacade)
	             .map(value -> (EquipmentFacade) value)
	             .collect(Collectors.toList());
}
 
Example 4
Source File: EquipInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static List<EquipNode> getMenuTargets(JTable table, MouseEvent e)
{
	int row = table.rowAtPoint(e.getPoint());
	if (!table.isRowSelected(row))
	{
		if ((row >= 0) && (table.getRowCount() > row))
		{
			table.setRowSelectionInterval(row, row);
		}
	}
	return Arrays.stream(table.getSelectedRows())
	             .mapToObj(selRow -> table.getModel().getValueAt(selRow, 0))
	             .filter(value -> value instanceof EquipNode)
	             .map(value -> (EquipNode) value)
	             .collect(Collectors.toList());
}
 
Example 5
Source File: PurchaseInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static List<EquipmentFacade> getMenuTargets(JTable table, MouseEvent e)
{
	int row = table.rowAtPoint(e.getPoint());
	if (!table.isRowSelected(row))
	{
		if ((row >= 0) && (table.getRowCount() > row))
		{
			table.setRowSelectionInterval(row, row);
		}
	}
	return Arrays.stream(table.getSelectedRows())
	             .mapToObj(selRow -> table.getModel().getValueAt(selRow, 0))
	             .filter(value -> value instanceof EquipmentFacade)
	             .map(value -> (EquipmentFacade) value)
	             .collect(Collectors.toList());
}
 
Example 6
Source File: DataRowTable.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 *  returns a JLabel that is highlighted if the row is selected.
 *
 * @param  table
 * @param  value
 * @param  isSelected
 * @param  hasFocus
 * @param  row
 * @param  column
 * @return
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
  if(table.isRowSelected(row)) {
    int[] i = table.getSelectedColumns();
    if((i.length==1)&&(table.convertColumnIndexToModel(i[0])==0)) {
      setBackground(PANEL_BACKGROUND);
    } else {
      setBackground(Color.gray);
    }
  } else {
    setBackground(PANEL_BACKGROUND);
  }
  if(value==null){ // added by W. Christian
	  setText("???");  //$NON-NLS-1$
  }else{
	  setText(value.toString());
  }
  return this;
}
 
Example 7
Source File: TraceTableCellRenderer.java    From pega-tracerviewer with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    TraceEvent te = (TraceEvent) value;

    if (te != null) {

        TraceTableModel traceTableModel = (TraceTableModel) table.getModel();
        TraceTableModelColumn traceTableModelColumn = traceTableModel.getColumn(column);

        String text = te.getColumnValueForTraceTableModelColumn(traceTableModelColumn);

        super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);

        if (!table.isRowSelected(row)) {
            boolean searchFound = te.isSearchFound();

            if (searchFound) {
                setBackground(MyColor.LIGHT_YELLOW);
            } else {
                setBackground(te.getColumnBackground(column));
            }
        }

        setBorder(new EmptyBorder(1, 3, 1, 1));

        setToolTipText(text);

    } else {
        setBackground(Color.WHITE);
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }

    return this;
}
 
Example 8
Source File: DataTable.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 *  returns a JLabel that is highlighted if the row is selected.
 *
 * @param  table
 * @param  value
 * @param  isSelected
 * @param  hasFocus
 * @param  row
 * @param  column
 * @return
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
  if(table.isRowSelected(row)) {
    int[] i = table.getSelectedColumns();
    if((i.length==1)&&(table.convertColumnIndexToModel(i[0])==0)) {
      setBackground(PANEL_BACKGROUND);
    } else {
      setBackground(Color.gray);
    }
  } else {
    setBackground(PANEL_BACKGROUND);
  }
  setText(value.toString());
  return this;
}
 
Example 9
Source File: TraceTreeTableCombinedTree.java    From pega-tracerviewer with Apache License 2.0 4 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    TraceEventCombinedTreeNode traceEventTreeNode = null;
    TraceEvent te = null;

    if (value instanceof TraceEventCombinedTreeNode) {
        traceEventTreeNode = (TraceEventCombinedTreeNode) value;
        te = (TraceEvent) traceEventTreeNode.getUserObject();
    }

    if (te != null) {

        String text = traceEventTreeNode.getNodeValue(column);

        super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);

        if (!table.isRowSelected(row)) {

            boolean searchFound = traceEventTreeNode.isSearchFound();
            boolean leafSearchFound = te.isSearchFound();

            if (leafSearchFound) {
                setBackground(MyColor.LIGHT_YELLOW);
            } else if (searchFound) {
                setBackground(MyColor.LIGHTEST_YELLOW);
            } else {
                setBackground(te.getColumnBackground(column));
            }
        }

        // setBorder(new EmptyBorder(1, 3, 1, 1));

        // setToolTipText(text);

    } else {
        setBackground(Color.WHITE);
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }

    return this;
}
 
Example 10
Source File: TraceTreeTableCombinedCellRenderer.java    From pega-tracerviewer with Apache License 2.0 4 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {

    TraceEventCombinedTreeNode traceEventTreeNode = null;
    TraceEvent startEvent = null;
    TraceEvent endEvent = null;

    if (value instanceof TraceEventCombinedTreeNode) {
        traceEventTreeNode = (TraceEventCombinedTreeNode) value;
        startEvent = (TraceEvent) traceEventTreeNode.getUserObject();
    }

    if (startEvent != null) {

        String text = traceEventTreeNode.getNodeValue(column);

        boolean searchFound = false;
        boolean leafSearchFound = false;
        Color background = null;

        endEvent = traceEventTreeNode.getEndEvent();

        if ((endEvent != null) && (!(endEvent instanceof TraceEventEmpty))) {
            searchFound = traceEventTreeNode.isSearchFound();
            leafSearchFound = startEvent.isSearchFound() || endEvent.isSearchFound();
            background = endEvent.getColumnBackground(column);

        } else {
            searchFound = traceEventTreeNode.isSearchFound();
            leafSearchFound = startEvent.isSearchFound();
            background = startEvent.getColumnBackground(column);
        }

        super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);

        if (!table.isRowSelected(row)) {

            if (leafSearchFound) {
                setBackground(MyColor.LIGHT_YELLOW);
            } else if (searchFound) {
                setBackground(MyColor.LIGHTEST_YELLOW);
            } else {
                setBackground(background);
            }
        }

        setBorder(new EmptyBorder(1, 3, 1, 1));

        setToolTipText(text);

    } else {
        setBackground(Color.WHITE);
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }

    return this;
}
 
Example 11
Source File: TraceTreeTableCellRenderer.java    From pega-tracerviewer with Apache License 2.0 4 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    TraceEventTreeNode traceEventTreeNode = null;
    TraceEvent te = null;

    if (value instanceof TraceEventTreeNode) {
        traceEventTreeNode = (TraceEventTreeNode) value;
        te = (TraceEvent) traceEventTreeNode.getUserObject();
    }

    if (te != null) {

        String text = traceEventTreeNode.getNodeValue(column);

        super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);

        if (!table.isRowSelected(row)) {

            boolean searchFound = traceEventTreeNode.isSearchFound();
            boolean leafSearchFound = te.isSearchFound();

            if (leafSearchFound) {
                setBackground(MyColor.LIGHT_YELLOW);
            } else if (searchFound) {
                setBackground(MyColor.LIGHTEST_YELLOW);
            } else {
                setBackground(te.getColumnBackground(column));
            }
        }

        setBorder(new EmptyBorder(1, 3, 1, 1));

        setToolTipText(text);

    } else {
        setBackground(Color.WHITE);
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }

    return this;
}
 
Example 12
Source File: TraceTreeTableTree.java    From pega-tracerviewer with Apache License 2.0 4 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    TraceEventTreeNode traceEventTreeNode = null;
    TraceEvent te = null;

    if (value instanceof TraceEventTreeNode) {
        traceEventTreeNode = (TraceEventTreeNode) value;
        te = (TraceEvent) traceEventTreeNode.getUserObject();
    }

    if (te != null) {

        String text = traceEventTreeNode.getNodeValue(column);

        super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);

        if (!table.isRowSelected(row)) {

            boolean searchFound = traceEventTreeNode.isSearchFound();
            boolean leafSearchFound = te.isSearchFound();

            if (leafSearchFound) {
                setBackground(MyColor.LIGHT_YELLOW);
            } else if (searchFound) {
                setBackground(MyColor.LIGHTEST_YELLOW);
            } else {
                setBackground(te.getColumnBackground(column));
            }
        }

        // setBorder(new EmptyBorder(1, 3, 1, 1));

        // setToolTipText(text);

    } else {
        setBackground(Color.WHITE);
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }

    return this;
}
 
Example 13
Source File: TracerReportRulesTableModel.java    From pega-tracerviewer with Apache License 2.0 2 votes vote down vote up
private DefaultTableCellRenderer getDefaultTableCellRenderer() {

        DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer() {

            private static final long serialVersionUID = 1504347306097747771L;

            /* (non-Javadoc)
             * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
             * java.lang.Object, boolean, boolean, int, int)
             */
            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                                                           boolean hasFocus, int row, int column) {

                RulesetRule rulesetRule = (RulesetRule) value;

                if (rulesetRule != null) {

                    String text = getColumnValue(rulesetRule, column);

                    super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);

                    if (!table.isRowSelected(row)) {

                        TraceEventRule traceEventRule = rulesetRule.getTraceEventRule();

                        Color backgorund = traceEventRule.getBackground();

                        setBackground(backgorund);

                    }

                    setBorder(new EmptyBorder(1, 8, 1, 1));

                    setToolTipText(text);

                } else {
                    setBackground(Color.WHITE);
                    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                }

                return this;
            }
        };

        return dtcr;

    }