Hide/Open JTable by a press of a button in JScrollPane - java

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?

Related

Hide title of JTable when form is loading?

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();

JComboBox with 4 cols and 4 rows data[][] form

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.

Save Button from Menu Bar

Good Morning,
I have built a Main Form with a MenuBar, in this MainForm I put a layeredpane where I show a JInternalFrame.
In my MenuBar I had put a JButton (Save). I would like that when I click on Save button I can retrieve the data from the mentioned JInternalFrame.

JFrame window with sub components

So I have created this JFrame window which has a lot of items like JLabel, JComboBox JTextField etc… At the bottom it has a "next" JButton.
I want that when a user clicks the next button, everything on the screen should be removed and replaced with stuffs from other class that I have created.
I only manage to open a new JFrame window whenever I click the next button. Can somebody please tell me how to remove all items from the screen and replace them with items from another class.
Thanks. I am a newbie so please give me the easiest way possible.
This sounds like a job for CardLayout
You could create a base panel in the BorderLayout.SOUTH position of your JFrame that would have your navigation buttons and have a number of panels added to your main panel being managed by CardLayout.
See Creating Wizard Dialogs with Java Swing
While the systematic thing for it is using CardLayout, you can imitate it if you don't want to learn how to use it!!
Create a Panel, add all items except the next button to this panel. Use BorderLayout to put the panel on top of the next button in the frame.
Now when the user press the next button you remove the panel (jframe.remove(panel)). create a new JPanel and add it using the BorderLayout again on top of the next button.

Get focus on a JTextField from another panel when a CardLayout changes

hi need help on a Swing application that I am doing. I have a dialog with two panels, the first panel has a CardLayout and the second has a FlowLayout. The first layout has buttons that change the card layout and the buttonclick is entered to a specific textfield on the second panel. Every time the card layout changes, the textfield on the second panel loses its focus. How to get the focus of a specific textfield of the second panel?
when you are clicking on a button to go anohter panel
write the code inside the "actionPerformed" of that button
actionPerformed(ActionListenet al)
{
//code..
textField.requestFocus();//what the textfield u wnat
}
refer this link Setting the focus to a text field

Categories