So I already accomplished inserting a component in a table using a button event. The next thing I'm trying to do is add the same component in the table for example a Select Component that has the items A and B. Everytime I clicked the button a the Select Component appears then I clicked the button again to create another row of components but the Select Component transfers to the second row rather than adding a new one. So how to do this?
Thanks.
Every Component (e.g. Button or Select) you see has its own representation on the server. You can't show the same Component more than once. Generate a new Select component for every row you add to the table. You might want to read the part about FieldFactorys (5.16.3) in the vaadin book.
Related
I want, in a JTable, has a column that when it is clicked, a JPanel to appear with the names of all the columns, and it can select (with JCheckBox) which we want to continue in the JTable. It would be a column with "#".
Just create such a column in your data model implementation, with a custom artificial data object. Then register an editor (setDefaultEditor) in the jtable to show a checkbox or open a dialog with a checkbox. based on the user selection you may then alter your model (add or remove columns) and fire an according changed event.
Not exactly what you asked for but maybe you can use the Table Column Manager.
The Table Column Manager manages which columns are visible in the table. You invoke the Table Column Manager by right clicking on any column in the column header. You are presented with a popup menu that uses check boxes to hide/show columns.
Using a JTable, my Table Model setValueAt() method moves the selection to the next row in certain cases, using setRowSelectionInterval() and setColumnSelectionInterval(). When it's called from the (default) cell editor (by user typing in the cell and hitting tab), the code works: the desired next cell is selected (the first one on the next row).
However, if the user uses Return rather than Tab to commit the edit, the selection doesn't happen; instead the cell below is selected. That's fine with me.
I also have a JButton to clear a row. The button's action function calls the model's setValueAt() function for the desired cells. Unfortunately, the setRowSelectionInterval() and setColumnSelectionInterval() methods have no apparent effect; instead, no cells are selected.
I've tried table.requestFocusInWindow() and table.getParent().requestFocusInWindow(), as well as table.changeSelection(row, 0, false, false), all to no apparent effect.
Is there anything basic I'm missing here, before I go to the trouble of building the SSCCE?
In case it matters, here's the container hierarchy:
parent JPanel
button rows JPanel
button row 1 JPanel
button row 2 JPanel
table JScrollpane
JTable
The button in question is in button row 1.
Thanks!
Maybe you can use the Table Cell Listener to listen for edits to the table. It listens for actual changes done by the JTable editor.
Then in the supplied Action you can select the appropriate row. You may need to wrap the Action code in a SwingUtilities.invokeLater(...) to make sure the code executes after the table is completely finished editing.
I have a JTable which contains names returned from a search in database. I want to use the names as buttons, when we click on them the program redirect to another frame with more details of the nameholder. Can I do that ?
This is easy to do, add the mouse listener to the table and use columnAtPoint and rowAtPoint to determine what has been clicked.
If you want a table cell to look like a button, set a renderer that uses JButton.
I want to use the names as buttons, when we click on them the program redirect to another frame with more details of the nameholder.
You need to create a custom renderer and editor for your table. Read the section from the Swing tutorial on Concepts: Editors and Renderers for basic information.
Then you can check out Table Button Column which is an example of a render/editor that you can use. You will need to provide your own custom Action to display the details.
I am creating an application where I have 3 Panes with buttons which dynamically create buttons in the next pane depending on the selection, clicking the last button shows a table of data brought up via an SQL query:
[buttonPane1][buttonPane2][buttonPane3][table]
If a user has clicked a button on all 3 panes and then wants to change their choice on buttonpanel1, it will bring up the choices in buttonpanel2 and using
buttonPanel3.removeAll();
buttonPanel3.repaint();
I can clear the third button panel, my problem is how to clear the table. I want to remove it from the Table ScrollPanel however if I try
tableScrollPanel.removeAll();
it just means that the table never shows.
How can I remove any current table but allow a table to be 'reattached' I am doing this to create and 'attach' the table
jTableTemp.setModel(new DefaultTableModel(
tableContent, tableTitles));
tableScrollPanel.setViewportView(jTableTemp);
Thanks Very Much
Try setting the table model to a DefaultTableModel with empty data and the original headers, then repaint. As long as you have a JScollPane wrapped around the JTable, the headers should show up, assuming this is what you want.
Other wise, you can set the viewport to a new instance of a JTable with new headers.
I want to implement following functionality but I am confused if it's possible in Java. If yes, than how? Please help:
I want to create a JTable kind of table where 1st row of table contains column names and an icon in each column i.e. in each cell of 1st row. Clicking on that icon should lead to removal of that column from table (possible using MouseListener??).
I have found many solution where I can add button to a cell in JTable but none which describes adding both text and icon (with MouseListener) to a cell. Please see if you can help and thanks a lot for reading.
You can create a custom TableCellRenderer that extends JLabel. This JLabel can be created with an icon (JLabel can display icons, to the right or left of the text). You will want the getTableCellRendererComponent to test wether the row being rendered is the first or not, and if so, set the icon, otherwise do not.
For the removal action, you can add a MouseListener on the table, and when processing the mouseClicked method, you can find the cell that was clicked in by testing the rowAtPoint and columnAtPoint by creating a Point from the mouseEvent.getX() and mouseEvent.getY(). If you determine the first row with the icon was clicked, you can remove the column from the column model.
If by 1st row, you actually mean the table header, you can create the same renderer for the JTableHeader, and set the MouseListener on that component.
Well, I don't understand your question.
I want to create a JTable kind of
table where 1st row of table contains
column names and an icon
Do you mean the Table Header, like the way sorting works by displaying the column name and the sort direction?
If so then you use a custom renderer for the table header and add a MouseListener to the header to determine which column was clicked. You should be able to customize the Default Table Header Renderer to do what you want.
Or do you mean the first row of data in the table. If so then you still need to use a custom renderer but this time you add the MouseListener to the table not the table header.
In both cases you can use the TableColumnModel.removeColumn() method to remove the column from the view of the table.