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
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'm developing a game as college work, I've a fully autonomus panel that handles all process of the game, but I want to add a menu that allows to select the differents levels and difficulties, and there's the problem.
I only have one frame, so I've to manage two panels in this. How can I change the panels? I've read something about CardLayout, but I don't know if it's that I need really.
I'm doing tests adding and removing the panels , but It doesn't work fine. How can I do it?
Edit I think that the problem is the previous panel is not removed, so the add/remove way doesn't work.
CardLayout, but I don't know if it's that I need really. ..
Yes, it is.
I'm doing tests adding and removing the panels , but It doesn't work
fine.
please is there some, for why reason to simulate CardLayout
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.
I have about 3 frames in my java swing application. What it the correct way how to handle with these frames? I mean some pattern or something else. Now I have always one class which represent frame and one class for panel which is main in this frame. Now I have defined frames as static variable and when I wanna hide them I call
classname.frameName.setVisible(false);
is this the correct solution?
Besides the (excellent) suggestions of a CardLayout or JFrame with multiple JDialog instances, here are some other strategies which might work singly or in combination, to collapse a variety of content panes into a single frame.
JDesktopPane/JInternalFames (Tut.).
JSplitPane (Tut.).
JTabbedPane (Tut.).
JLayeredPane, if you're feeling brave (Tut.).
JToolBar - floatable if needed (Tut.).
Different constraints of a JPanel in a nested layout.
There are probably more..
Of course, as Adamski pointed out, there are some further quirks to consider..
What if each frame has JMenuBars or JMenus?
Possibly combine them as sub-menus.
Take a look at a decent docking framework such as MyDoggy. This allows you to display all three components in a single JFrame, but is very flexible in that you can view the data side-by-side, resize and maximise components.
This design seems flawed. Instead of having multiple containers, you should use an appropriate layout manager. In this case, I recommend using CardLayout. This way, you would have a single container with multiple exchangeable views.
Controlling frames through static references seems to be a very fragile solution. What if the reference is null? What if the frame isn't in a completed state when setVisible() is called on it?
It would probably be a better idea to separate this logic out into a separate class and either have the frames register themselves to it , or construct everything up front.
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.