Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

select complete column in TableView on click in cell

TPD-OpitzNov 2 2015 — edited Nov 6 2015

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

This post has been answered by TPD-Opitz on Nov 6 2015
Jump to Answer

Comments

Processing

Post Details

Added on Nov 2 2015
1 comment
855 views