I have a jlist of table names from a database and I was wondering if it is possible to drag and drop the table name to another jpanel and for that panel to execute the sql to retrieve store the information of that Table. I am not too savvy with swing. a class or method in which I can get a table to load from a drag and dropped jlist.
Hope this is legible.
Related
I have successfully displayed a JTable using an AbstractTableModel, but I want to add delete button for each row in the last column, in the getValueAt method that returns Object there is no way that I can return JButton, JLabel or any JComponent that is clickable. I tried that and I only get the object description toString.
Is there another solution to render JComponent in a JTable without using the TableModel approach?
Is there another solution to render JComponent in JTable without using the TableModel approach?
The TableModel is used to hold the data for the data for the model.
The JTable implements the view of the data for each column. The renderer is just a picture of the data. You can easily render the data to look like a button, however a renderer does not respond to any event.
The JTable does support editors and that is how you interact with real components. When you edit a normal cell a JTextField is placed in the cell location so you can type data into the cell and then the data is save to the model.
So if you want to click on a button then you need to use a button as an editor.
Check out Table Column Button for a class that uses a JButton as the renderer and editor. You then provide the class an Action to be invoked when the button is clicked.
Read the section from the Swing tutorial on Concepts: Renderers and Editor for more information. There is also a section on Using Other Editors.
One way : TableColumn.setCellEditor(jbutton_instance) on a hand added column.
How to hide jTable at jFrame in java GUI, not just hide the column, but entire jTable?
I was try to use table.setVisible(false), but just hide a column not entire table
You cannot hide the table, but you can hide your panel containing the table
instead.
yourPanel.setVisible(false);
Whenever you want to show the table do yourPanel.setVisible(true);
May I know how do I make a popup frame to do the insert of data since I'd like my GUI to popup another frame to ask for user input to the database and as well as the JTable? Thank you!
What I don't get is how to make use of the add button, then insert the entry and make the listener notice about "e.getType()==TableModelEvent.INSERT".
Edit:
At the same panel as the JTable, I would have an add button at the bottom. This add button would then in another 'frame' ask users to enter the items to add to the database as well as adding and refreshing the JTable.
you must use a DataModel with your JTable, and add item to your datamodel and then update your JTable with yout DataModel.
DefaultTableModel model = new DefaultTableModel();
JTable table = new JTable(model);
// Create a couple of columns
model.addColumn("Col1");
model.addColumn("Col2");
// Append a row
model.addRow(new Object[]{"v1", "v2"});
inserting new data from external class into jtable
Have a look at this , I hope your problem will be solved , Pass the Table reference in the constructor of your JFame/JDialogue (Better if you use JDialogue Instead of JFrame click here to know some good reasons) and modify table model accordingly
I have to develop a front end in Swing.I have a JFrame in Netbeans with 3 panes in it.
JScrollPane 1:it contains a JTable
JScrollPane 2: It should display the value of the fields of the selected row
ListPane : which contains the list of tables from which a user chooses a table to be displayed.
Now since the content of JTable varies(the no of rows and columns also vary) dynamically based on the table chosen by user I can't drag and drop the TextBoxes in the 3rd scroll pane to display the selected row's values.It would be helpful if anybody can suggest a way to do it or any pointers to problems that deal with similar issue
Add a ListSelectionListener to your JList. When a particular table is selected from the list, use setModel() to change the TableModel of your JTable to one that is correct for the chosen table. A related example using setModel() is shown here.
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.