alt text http://img202.imageshack.us/img202/2637/dialogo.png
I'm wondering how I could make this into a popup dialog. I designed this with Netbeans gui editor. I looked at option dialog, but all the examples only had a textfield or a combobox, not more than one thing like I have. So what would be the best way to make this in Java.
You should extend JDialog
See the dialogs tutorial
You can make a JDialog form
You could extend JDialog, then use GridBagLayout to implement GUI like that (actually JFrame also works, you just need to specify some setting like default close operations and stuff), if you use JDialog, set setModel() to true to block other GUI just like a pop up window.
Related
how can I turn off the first jframe after clicking a jbutton to open a second jframe? just like this.
this is what I want to happen in my GUI:
It sounds like you are talking about implementing a 'GlassPane'
A GlassPane is a technique where you place a new RootFrame layer over the existing components and use it to
Absorb all of the mouse events to prevent them from interacting with the components
Shade the UI to draw more attention to the other modal window or other frame
You can read about creating a glasspane/rootpane
and there are plenty of examples of its usage
A Swing application should only contain a single JFrame.
For the child window you can use:
a modal JDialog for a complex window when you want full control over the components on the dialog.
a JOptionPane for a easy to use pre configured "confirm" dialog. See: How to Make Dialogs for examples.
I already look at java library and dont know what to use to do this..
I already tryed JInternalFrame but thats not what I really want.. because it needs to be added to a JDesktopPanel right??
And in my program I have a JFrame with content pane using BorderLayout..
Then on borderlayout center I have a JTextArea, on borderlayout east I have a list.. and on borderlayout south I have a JPanel..
What I want is, when I do a certain action, it will pop up a "mini window" where I need to choose something.. u see?
and if I create JDesktopLane it will overlap what I have on the container..
the window will be made by my like a color chooser pallete , like a grid with colors.. and a label on top saying some text..
I just dont know how to make a "window" over the other components, and users can still drag over the frame, and interact with all the other components.. the jtextarea and such..
I guess you understood, thanks alot in advance!!
If u dont understand something please tell me, I really want to do this :)
Just dont know what to use..
Thanks again ;)
Have you tried JDialog?
It's because Jdialog are not component to be add in a JFrame, it's an independant thing running on it's own
if you use JDialog, the construct parameter parent indicate wich frame the JDialog is related to.
The typical class for this task is JWindow, a borderless top-level window that can be freely positioned. You could use SwingUtilities.getPointFromComponent to get the screen coordinates for a realized coordinate.
Top-level windows (JFrame, JDialog, JWindow) are not added to containers. They can get other windows as parent.
I dont want to use another JFrame.. that is kinda bad for code, its a small window with a simple function..
Structure your code so you can read it, others can read it, and you can debug it easily (the latter is a result from the first). A low class count is useless and -most of the time- contraproductive.
Why should another JFrame (or other window) be bad?
If you absolutely want to avoid opening top level windows (e.g. to avoid applet warning icons or to implement a special kind of user interface) you could use a JLayeredPane to add additional JPanels above your existing GUI elements.
I am developing an application which needs to pop up new JFrame B with different components, when I click on a button on JFrame A. How do I achieve that?
I don't want to use the tabs.
Use a JDialog , problem solved!
See this java tutorial for more help : How to Make Dialogs
I'm not sure why no one has suggested CardLayout yet, but this is likely your best solution. The Swing tutorials have a good section on this: How to use CardLayout
In a nutshell (a simple solution), you register a listener with the JButton and then have the listener perform the tasks you want it to perform:
setVisible(true) for one frame.
setVisible(false) for the other one.
Regards!
One way to approach this would be to create another jFrame and then add a listener onto your button like so:
jFrameNew.setVisible(true);
This way you have a whole new frame to work with. If you want to just have a pop-up message you can also try using the jDialog frames.
Depending on which IDE you are using...for example Netbeans has a gui that makes designing interfaces slightly easier, so you can test out the different frames.
I need to make a popup box with with a combo box and a couple of buttons. Please could someone advice on the best way to achieve this? I've had a look around and all I can find is alert boxes. Is this possible or will I need to create a whole new frame?
You can use the JOptionPane to achieve this. Please refer to the link below which explains this with sample code:
http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#input
JOptionPane.showInputDialog may be good enough if you are willing to leave how exactly the options are presented up to the UI.
I need to make a popup box with with a combo box and a couple of buttons
1) don't use another JFrame as popup window, use JFrame with JOptionPane/JDialog/JWindow these container are same as JFrame, but can take parent and owner
2) don't forget to setParent
3) depends if you needed decorated window then use JDialog, don't forget look for setModal() or ModalityTypes, if undecorated then use JWindow
4) don't create lots of JOptionPane/JDialog/JWindow on fly, becasue there Object are still in JVM memory, create this Container once and re-use that (by removing child) for another Action
I want to implement some functionality in a library and make it available as a GUI building block for my applications. I think I would like to implement it as something that extends a JPanel, so it can be embedded as a component in other windows.
Is there a reason I should use a JDialog instead? How easy is it to create a JDialog which displays a JPanel along with minimal other appropriate components? (e.g. just a border/closebox/etc for modeless dialog; for modal, the same + an OK/Cancel)
You should extend JDialog only if you want a Dialog, and if you want just a Panel that you can use in other Windows or Frames you should extend JPanel.
Yes, it is easy to create an JDialog just containing a JPanel with a border, closebox and OK/Cancel, both modal and not modal.
Have a look at How to Make Dialogs and How to Use Panels
I would make it a JPanel. That way you could reuse it in other components or drop it into a JFrame (by calling setContentPane) if you want to run it as a standalone. The only reason for you to need a JDialog is if you want to make your component modal.