I need to hide the JTable from frame, when its loading, and it's visible based on some contition(ex: when click the textfield, then JTable will show).
i tried, but i don't have a luck.
code:
jTable1.setvisible(false);
(or)
jTable1.hide();
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.
I want to represent data split into groups (categories) and when pressing a button of a category I want JTable to show below category button. I've built JScrollPane on it is placed JPanel which is a container of costume made panels (BoxLayout is used for placement in the container).
Costume made panel (CMP) to show category with a function to hide or show JTable
Now the problem is when i press button to show or hide table function is executed in code of CMP but JScrollPane does not refresh and does not show the action. It refreshes when you click on scroll bar. What can i do about it? Is there any better way to build something like this?
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);
For most items within Java, you simply add .setVisible(false). Then the item disappears from the form, but when I do this for a Jtable within Netbeans, using:
table1.setVisible(false);
Rather the table going invisible, it goes grey instead. Shown in picture below:
How do I get this to work?
You need to call reset() and revalidate() on the container that holds the JTable after making it invisible.
You shouldn't be making it invisible anyway, yes perhaps the JScrollPane that holds it, but not the JTable itself.
You've misspelled "Length".
In my Java Swing app, I need to have a JComboBox with four columns and four rows. Basically, it's a combo box to select color. When the combo box is collapsed, the user can see the first row's four columns, and when it's expanded, the user can see sixteen colors in 4x4 form.
I am not sure how to design such a combo box layout. I can use a renderer, but I'm not sure about how to implement it. I can only see two possibilities:
Create a JLabel named "ColorLabel" that draws a circle and fills the color of the circle as specified in its constructor.
Create a panel "ColorRowPanel" and add four ColorLabels in it. Create four objects of ColorRowPanel and set that as the model to the combo box.
Create a JTable of 4x4 and add ColorLabel in each cell. Set the JTable as the model of the JComboBox.
Is any of this possible? If so, in what object do I add my ColorRowPanels/JTable to set as the model? And when a color is selected, I should be able to know which colorLabel or which row-col is selected to get the color selected by user.
UPDATE
Thanks. As per your guidances, I started up.
1) Created a class ColorButton of type JToggleButton - just to create a shape for the button. Nothing more is implemented. Code taken from here
2) Created a class ColorContainer that extends AbstractColorChooserPanel. Created a Panel of 4 btns and added 4 such panels to the class. Also implemented ButtonGroup to each button of the panels. Designed as shown in CrayonPanel - added my initComponents() in buildChooser(). Constructor is empty. Rest all abstract methods are empty as per now.
3) Added panel to JCC and using JDialog.createDialog could show the ColorContainer. It comes properly fine, just I don't want the Ok, Cancel, Reset btns. I didn't find any option in JCC class or on net to hide the buttons panel of JCC dlg.
4) To try the same with Panel, I made ColorContainer extend JPanel instead of AbsColorChooserPanel and show the ColorContainer in Popup and it shows perfectly well.
I can't get way for 2 things yet -
1) MAIN - I want results like this :
1st part shows when the dropdown is collapsed & 2nd when it is shown. You see the 1st panel is still visible regardless of drop down been shown or collapsed.
What I got till now is : I added a JLAbel and on mouseEnter event I show the popup.
How do I achieve the results as I want to ? Can't think of a way to implement this.
2) Is it possible to hide the btns of JColorChooser and get the results as I am expecting !!
Please guide me and help me.
You cannot use combobox here. Combobox is designed to have 1 element in each popup row.
You should create a Panel with 4 buttons for the selected row and additional button to open the popup with 12 another buttons. To create the popup see the class javax.swing.Popup.
Here is the step-by-step guide:
Create panel with 4 color toggle Buttons and the button to open the
popup.
Create Panel with 12 another color buttons.
Add all color buttons to a ButtonGroup
Make trigger to open/close popup and add it to the button to open
the popup
Make trigger to close the popup if one of the color buttons is
switched and add it to all color buttons.