How to put maximize and minimize buttons in a jDialog? - java

my question is very simple. I am creating an app with Java swing, and i realized that the jDialogs doesn´t have maximize and minimize buttons, instead of the jFrame.
There is a way to add it to it? or if not, what can i do if i want to replace the jDialog to another swing component that it has?
Thanks a lot!

To answer my question, i have used the cardLayout to create differents jPanels and including into my jFrame, every time that i want to show another "window" i change it to the corresponding jPanel..
You can see the documentation of cardLayout here:
https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html

Related

JavaFX switching between two panes in a UI

I need to give the user of a UI the option to switch between two border panes on clicking a button (or toggle switch or whatever).
The panes have the same job, size and position - it's just a different configuration so I don't want both of them there at the same time.
When designing the UI in SceneBuilder I cannot place them at them same spot and set one visible and one invisible - because SceneBuilder obviously doesn't know that I want to stack them on top of each other.
Is there a way I can include both of them in the UI but only show one at a time?
I'd appreciate any ideas :)!
What you are looking for is the CardLayout. See oracle's documentation on that: https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
Instead of adding your Components directly to the Component with the BorderLayout, instead add a JPanel which is using the CardLayout. Add the two Components to this JPanel.
Unfortunately I have no way to test this with the SceneBuilder right now, but you'll figgure out, how that works ;)

Java Swing: JPanel only adds components when JFrame window is maximized or it's size changed

I have a Java program that creates a JFrame, a JPanel, and several JTextAreas. I set the text of the JTextAreas and then add them to the JPanel. When the program loads, I only see the empty JFrame.
However, if I maximize, or change the size of the program window, the JTextAreas, and their respective texts appear on the screen.
How can I correct this so that the program loads, with the text areas populated, without the need to mess with the window? My apologies in advance for being a Swing noob.
My guess: You need to call setVisible(true) on the JFrame after adding all components to it.
Next time, or this time if this doesn't answer your question, please post pertinent code. We're terrible at reading minds or guessing at code not shown. Please check out the Jon Skeet blog: Asking the Perfect Question. It will give you great suggestions on how to create better more complete questions and thus get better answers.

Swing method to show or hide part of a panel on button click?

I'd like to be able to show and hide (and therefore grow and shrink the jpanel as appropriate) in my swing application. I've seen something similar on websites that I imagine uses JS and JQuery.
What I'm after is the ability to click a button (that might say 'Advanced options') that then 'slowly' grows the panel and reveals (setVisible(true)) components.
Is this possible using Swing? I've tried looking round the web, and SO but I only seem to get JQuery questions, or unhelpful Java posts. This is the closest I've found.
Use a Swing Timer to animate your slide. For example, this link has code that places the components in a JLayeredPane and slides one component over the other, again using a Swing Timer: slide effect with JPanel.
Another useful effect is to fade out from one JPanel to another. For an example of this that uses a Swing Timer as well as a CardLayout, please check out this answer.

Java - Placing of few buttons and textboxes using SWT

I need to place few buttons one under another and few textboxes in the same way using SWT.
When I'm doing that, they are next to each other and I cannot change it even using
button1.setLocation(new Point(100,20));
button2.setLocation(new Point(400,10));
Can I add those things to something similiar to SWING's JPanel and move/position it freely as I need? Or maybe another solution? As to let You know - I cannot use SWING here. It has to be SWT. The reason is that I have already a chart made with SWT. The buttons and textboxes should be placed so they won't be covering my chart.
You can dynamically add a new control to the existing layout, but make sure you call the layout() on the parent Composite, where you have set the layout.
If you want to place a SWT control relative to another control, you can use org.eclipse.swt.layout.FormLayout.

Images in Swing GUI-NetBeans

I already designed many JPanel's for my application in Netbeans now i want to ..
Add background images to all jpanel's in which i had some jcomponents already.
And i want it to do it for jdialog too.
I need to design a JMenu with images and menu name.
But already i saw many examples for background images in that they are adding there components through coding im doing it in Netbeans.Is it possible to set it for the main JFrame then i can leave the jpanel's.
If you use netbeans background image can be added using a simple method. I don't know whether it is a good practice, but it is really easy. See this video.

Categories