Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use <code>JPanel</code> with <a href="http://docs.oracle.com/javase/6/docs/api/java/awt/GridLayout.html" rel="nofollow">GridLayout</a> as the cell renderer:</p> <pre><code>public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,int row,int col) { if (isSplitted(value) { JPanel panel = new JPanel(new GridLayout(1,2)); JLabel left = new JLabel(getLeft(value)); JLabel right = new JLabel(getRight(value)); panel.add(left); panel.add(right); return panel; } else { return super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, col) } } </code></pre> <p>Here <code>getLeft</code>, <code>getRight</code> and <code>isSplitted</code> are up to you to define for the value you render in that cell.</p> <p>If makes sense, you can also optimize retaining an instance of this panel with the two labels; it is possible to reuse it on every call upon setting the required content. For the case when left and rights components are very different in size, BorderLayout may work better.</p> <p>Similarly, you can provide the cell editor, just you need <code>JTextField</code> or the like as <code>JLabel</code> is not editable. Derive from <a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/swing/AbstractCellEditor.html" rel="nofollow">AbstractCellEditor</a>, overriding <code>getCellEditorValue</code> (return the value composed from the panel) and <code>getTableCellEditorComponent</code> (return the panel itself after setting the fields to the current value).</p> <p><strong>@Stifler</strong> has commented on my answer:</p> <pre><code>public Component getTableCellRendererComponent(JTable table, Object obj, boolean isSelected, boolean hasFocus, int row, int column) { Component cell = super.getTableCellRendererComponent( table, obj, isSelected, hasFocus, row, column); JPanel panel = new JPanel(new GridLayout(1, 2)); if ("History".equals(obj)) { JTextField left = new JTextField("Left"); left.setEditable(true); JTextField right = new JTextField("Right"); left.setEditable(true); panel.add(left); panel.add(right); return panel; } return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload