Forum Stats

  • 3,826,050 Users
  • 2,260,591 Discussions
  • 7,896,781 Comments

Discussions

select complete column in TableView on click in cell

TPD-Opitz
TPD-Opitz Member Posts: 2,465 Silver Trophy
edited Nov 6, 2015 3:00AM in Java 8 Questions

hello,

I need a dialog where the user can select a column to use the columns data later in process.

The data in the table is read only.

in Swing I'd simply call

jTable.setColumnSelectionAllowed(true);
jTable.setRowSelectionAllowed(false);

but how du I get the same behavior in JavaFX-8 as with this swing-SSCCE?

public class TableSelectTest {
    public static void main(String[] args) {
        TableModel myModel = new DefaultTableModel(5, 5) {

            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }

            @Override
            public Object getValueAt(int row, int column) {
                return String.format("%s-%s", Character.valueOf((char) (0x41
                        + row)), column);
            }

        };
        JTable jTable = new JTable(myModel);
        jTable.setColumnSelectionAllowed(true);
        jTable.setRowSelectionAllowed(false);
        while (4 > jTable.getSelectedColumn()) {
            JOptionPane.showMessageDialog(null, jTable, "select a column", JOptionPane.QUESTION_MESSAGE);
            JOptionPane.showMessageDialog(null,
                    String.format("column %s selected", jTable.getSelectedColumn()),
                    "result",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    }
}

bye

TPD

Best Answer

Answers