I want to put one toolbar type component in which there will be one button which when pressed the toolbar should expand, size of the form increases and it contains some components like text area and label that user can see and once again when the button is pressed the toolbar is minimized and the size of the form decreases.
Can anybody tell me how to accomplish this?
e.g; like in windows 7 in my computer there is one toolbar called "Hard Disk Drives". When we press on it it shows all the drives and when we again press it it hides it.
SwingX has a collapsible panel control that I think should do what you want.
Also take a look at How to have Collapsable/Expandable JPanel in Java Swing.
Some alternatives:
You can add a JButon to a JToolBar. In your button's ActionListener, open a JOptionPane containing your components. This example illustrates some possibilities.
For a more advanced view, consider Outline, illustrated here.
Related
I am designing a game for a project in Java Swing using a JForm. I know that you have to use the code
jPanel1.setVisible(true);
I used this for all panels, even in the init() method in the source.
I am using the "Layered Panel" option for every panel I add. I placed the image on the first panel:
There are radio buttons in my second panel. I want the user to click on the option while looking at the picture, kind of like clicking on an icon (radio button) on desktop (background image).
Like this:
When I try to look at my design preview, it just shows me Panel2 (only radio buttons), not 1.
Is it possible to fix this (make two panels visible at once), or should I just make a button to switch between the panels?
I have designed a GUI using Swing components. I have added a Next Button and when someone press it I want to appear another layout of the same GUI. Something like when I pressed proceed in this site in order to write the question.
Sounds like you will want to use a CardLayout. You can define multiple panels to occupy the same space in the frame. You can swap the panel that is displayed based on your requirements.
So based on your question, the "Next" button would just display the next panel added to the CardLayout.
Read the section from the swing tutorial on How to Use CardLayout for more information and working examples.
I've searched extensively to solutions for this but haven't found anything that really achieves what I'm trying to do, the closest thing I could find was the solution posted at the bottom of this thread: http://www.java-forums.org/awt-swing/12267-how-add-jbutton-tabbed-pane-headder.html .
However because the JTabbedPane I'm using is inside a JSplitPane, it's size can increase/decrease, so using that solution doesn't work as the button stays static.
Below is an image of where I would like the place the component, similar to how eclipse has a minimize button on it's pop out views.
Is this possible without creating a custom JTabbedPane component?
Do you really need this button to hide?
Why don't you set splitpane.setOneTouchExpandable(true);?
With this line you can hide the bottom with an arrow of the splitpane.
I am creating a GUI for my project. I am completely stuck at one point. I was able to create a GUI which will make some simple queries like the release number, command name, and few other boolean questions.
Now I want the user to press CONTINUE button to move to the next page of the GUI form. I have created the continue button, but now I need to register an event to it. This is where I am stuck. I have no idea what event can I register to it which will move the GUI to next page. (By moving to the next page I mean, the different GUI pages we see when we are installing a software for our computer.)
For instance, if I am installing iTunes, I'd first select the radio button for "I accept the terms and conditions" and then I'd press the CONTINUE or the NEXT button to move ahead. If I need to come back, I'd press the BACK button.
One logical answer would be to create another GUI form and then link it to the one I created first.
EDIT:: this is the first time I am working in Java, so I might have ignored some obvious facts.
Look into using a CardLayout, adding several JPanels to the CardLayout-using container, and then to swap to the next view (the next JPanel), call the layout's next(...) method in the JButton's ActionListener. You could also randomly access components held by the CardLayout using its show(...) method.
To learn more about this including sample code, please have a look at the CardLayout Tutorial, and the API.
Well, register an ActionListener or an Action with the button. To do that wizard style, have a look at the CardLayout layout manager to switch cards or use a tabbed pane, hide the tabs and switch them inside the action or action listener.
if i understood, i think you should use the CardLayout
If you are using Swing, you can using several instances of JPanel over a one instance of JFrame.
You can have something like that structure:
JFrame
+------JPanel:root
|
+---JPanel:current // This panel change by other instance
|
+---JPanel:controlPanel // This panel contains you button
In you button need add a ActionListener with the method addActionListener
The panel control may need changes your elements, may the text of button or remove the listener and change by other.
I hope that can help
I'd like to create a set of buttons in a Java Swing application like you get in a typical tool palette in a paint program. That is, a set of small square buttons, each containing an icon, only one of which is pressed down, and when you press another button, the first is deselected. I've thought of a number of solutions and none of them seem very easy/elegant.
This sounds like a job for JRadioButton, but if you add an Icon to that, you still get the small circle, which is fairly space inefficient. I guess an option would be finding an alternative Look and Feel or painting code for JRadioButton.
Another alternative might be to add JButton to a ButtonGroup, maybe setting a JToggleButton.ToggleButtonModel as the model, but that doesn't have the desired effect, as the painting code for a standard JButton does not keep it depressed when selected. Possibly the JButton code could be modified to do this. Like making it painting "selected" the same way as "pressed".
A third alternative would be to use normal JButton's, and add a common mouse listener that keeps them pressed or not, and communicates the changes between the buttons.
Can anyone advise on the best way to achieve the aim please? A simple method I've missed would be best, but advice on which of these three alternatives would be best and pointers on how to get started would be useful too.
What about a plain JToggleButton in a ButtonGroup? It is not abstract, you can instantiate one with an Icon, and it stays depressed while selected.
See the SwingSet2 demo:
http://java.sun.com/products/plugin/1.4/demos/jfc/SwingSet2/SwingSet2.html
Click the second icon on the toolbar (the one twith the check box and radio button) then tab "Radio buttons". Then click on "Paint Border" on the right panel, under "Display Options".
Source code of the demo is under your JDK install dir, so for example on my PC it's under \jdk1.6.0_01\demo\jfc\SwingSet2\src