I've been staring at Oracle's JLayeredPane tutorials but they are laid out in a manner that is confusing to me and doesn't get at what I am trying to do.
I have an application that up to now has had no concept of layers. Everything is laid out in a single layer, inside a JFrame.
I now want to introduce a component that appears sporadically, as needed, in a certain location, overlaying existing components that stay there normally. Do I have to modify my existing application JFrame so that all its top-level contents (that is, the components that are directly added to the JFrame) are instead added to the JFrame's JLayeredPane?
Or what, exactly?
I'm looking for an easy way to adapt this gui to use layers with the minimum rework of the existing GUI.
Thanks in advance for any help here.
You may want to instead consider drawing your overlay element on the glass pane. That way you can leave the underlying structure completely as-is.
Related
I'm trying to make all my components to resize properly with JFrame Netbeans, but if I put the auto resizing to my components, it has like a margin between them, and if I try to put them together, it messes up the components , and I need them to be touching each other.
Thanks!
Double-click on the extra space between the components: it should open a dialog where you can change its size.
You can also click the extra space, and use the mouse wheel.
Netbeans form designer is very powerful and handy when you master it, but it requires some effort at first, especially for large user interfaces. If not already done, take some time to follow this tutorial: https://netbeans.apache.org/kb/docs/java/quickstart-gui.html
Also, if your user interface is large, it's better to break it in several smaller panels. You can design each panel independently with the form designer.
I was googling around for a while looking to imitate what our usual applications have in their designs: Multiple Frames (if I got that correctly)
I was wondering how can I achieve the same thing? I get the concept of (assuming I was able to accomplish making them) having layouts and resize managers inside my frame so that everything will still fit, but how can I add frames inside a jframe? how can I attach, detach, resize, turn them into tabbed frames?
anyone got a lead I can start reading about?
What you are looking for is called a cardLayout, and those are not Multiple frames inside a frame, they're basically multiple JPanels inside a JFrame.
When you use a cardLyout you can switch between panels inside your frame without needing to make another frame, this is very usefull and user-friendly compared to having multiple frames.
You could have a closer look at the Eclipse IDE source-code itself for example.
Find another starting point here http://www.vogella.com/tutorials/EclipsePlatformDevelopment/article.html
To expand upon the headline :
I have a screen (my main window, an encapsulated JFrame) that's going to be created most likely with a GridBagLayout, because I need a grid whose cells are to be differently-sized rectangles. In one of these rectangles will be a malleable dialog-like functionality, with different options depending on the context of the application.
My question is, are custom JDialogs the way to go here? Or do I simply want a reusable JPanel that has the particular buttons I want displayed or disabled depending on the context? I hope this is clear; thanks. -B.
Go with the JPanel solution.
JDialog is a heavy-weight, top-level container, meaning it's window is managed by the system and cannot be embedded as a child of another component.
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 have developed my Java code in Netbeans, and now I want to develop the GUI for my application.
The application communicates with a server, so it's going to have a login frame for sure. After that there will be a main frame. From the main frame the user can choose where to go and as you can understand there will be a lot of frames.
I have already developed a version of the application where there are a lot of frames and using the "setVisible()", but I want something better looking. I want a stable frame and inside it, changing the panels or something similar.
How would I do this?
You might use JInternalFrames if you like them, or simply use a main panel with a CardLayout, and display the appropriate card depending on the clicked menu item, or the selected JTree node (as it's done in Windows Explorer and similar applications).
Use the Swing tutorial to get you started.
You can, at any time, make any Container object a JFrame's ContentPane. You can also add and remove Containers from any other Container. If you want a user to be able to jump to any of a dozen panels at any time, CardLayout, as suggested in another answer, is easily the best route. If, however, you intend to lead the user along a somewhat controlled path, you can start with a login JPanel. When that's done, you can create the next panel (a JPanel or something else), add it, and dispose of the first one. And so on until the user exits.
If the transition from one panel to another affects nothing else in the program besides the two panels and the parent Container (JFrame or descendant), this is probably the way to go. If a bunch of other places in the program need to know about the change, you'll want a more centralized mechanism, maybe using CardLayout.