Using combobox as column header in javafx tableview - java

I am working with javafx2.2 and want to this thing don't know whether something already exist or not.
I need to add combobox to column header of a tableview but I want to retain functionality of clicking header and sort my data.
I know I can attach combobox using TableColumn.setgraphic(ComboBox); and use width of combobox and tablecol accordingly and have combobox on top of my column header but I don want this.
I want combobox to take complete space of my columnheader but with functionality of sorting on click.
Is it achievable? If yes then how?

Related

How to prevent the last box in a column from being editable JavaFX

I have a JavaFX TableView that I succeeded in making one of the columns editable using this:
colUnitPrice.setOnEditCommit(event ->
event.getTableView()
.getItems()
.get(event.getTablePosition().getRow())
.setUnitPrice(event.getNewValue())
);
The problem is I do not want the very last one to be editable as it contains a Label. Is there a way of preventing this?

Dynamically changing a JComboBox Cell Editor

The only sample I have is rather large so I am hoping to post this more as a general question to get an understanding of internal flow.
JTable has two JComboBoxes as Cell Editors for two different columns.
The select list within JComboBox2 will depend on the what is selected from JComboBox1.
This works for the most part.
When an item is selected from JComboBox1 the list dynamically changes behind the scene for JComboBox2.
The problem is the data is the cell itself doesn't change until I explicitly click on the JComboBox2 cell.
If in the code where I dynamically change the data for JComboBox2 I also explicitly change the cell data via the following call it works fine.
myTable.getModel().setValueAt(comboBox2.getModel().getElementAt(0), row, col);
Is this the expected process that both the ComboBox and Table models be updated?
Is there a way to simply update the ComboBox2 and have it automatically update what is seen in the JTable?

Get index of dynamic checkbox in java

I have dynamic checkbox in jtable , I do it by this code
TableColumn tcolumnas = jTable1.getColumnModel().getColumn(3);
tcolumnas.setCellRenderer(jTable1.getDefaultRenderer(Boolean.class));
tcolumnas.setCellEditor(jTable1.getDefaultEditor(Boolean.class));
and I want if I check one of them I want to know the index of check box.
Hearing for your suggestion
http://i.stack.imgur.com/tskSw.png
UPDATE :
the solution is veeery simple as here
Java Getting JTable Value (Per row)
You can add a TableModelListener to the TableModel. An event will be fired any time the data in a cell is changed.

How to restrain checking single checkbox in multiple columns in Jtable

I am trying to implement a Jtable which includes three check-box tables like this:
Can you tell me how to set a single selection group of checkboxes which only allows 1 selected check-box in a single row at any time?
I know of nothing out-of-the-box for doing this. I´d have a TableModelListener check these columns every time a change is made and call setValueAt on the checkboxes as needed.

Use of mouselisteners in a jTable

I have a jTable with columns 'Job_no' and 'Status'with values such as:
Job_no Status
1 Active
2 Pending
3 Pending
I would like it so that if a user clicks on a Status say in this case the first 'Pending'(where Job_no = 2) an inputDialog pops up allowing the user to change the status of the cell clicked-how can I do this? Bear in mind you will also have to retrieve the Job_no(that corresponds to that status) somehow, and that, though I'm OK with JOptionPane's, I'm new to JTables. I'm using JDBC(mySQL) and have a table 'Jobs' which amongst other things, has column Job_no and status.
Thanks for your help.
You don't do that by using a mouse listener and a popup, you just make the cells editable, and perhaps set a custom TableCellEditor. Take a look at the Java Tutorial for more details.
1) add a MouseListener to the JTable
2) Read the JTable API for the methods that will convert a mouse point to a row/column
3) Now that you know the row/column you can use the getValueAt(...) method to query the data in the Job_no column
4) Then you can change the status of the selected cell using the setValueAt(...) method.
So you break the problem down one step at a time.

Categories