How to "merge" two JFrames together? - java

I am desinging a GUI in Java using Swing.
I have two JFrames in my class which I would like to merge into one window, so that when the program is launched, only one window appears. However, my specific needs impose a specific layout constraint: I need to have half of my GUI displaying two components (a JTextArea component, and a JTextPane component), and the other half displaying the third one (an Image).
I can get them to all work singly, but if I try to combine them into a "super-frame" to hold them all, it doesn't work.
I am wondering is there any other way to achieve this effect.
Any help is much appreciated, thank you!

I think it is not possible to merge JFrames and you can instead use JPanels

Related

Manipulating multiple images and text

I'm trying to work out how best to approach creating a program in java where I have a very simple GUI where a user can drop in multiple images and multiple text boxes move these around by dragging, resize, maybe a couple of other very simple features and then output a jpg for instance.
I have been looking around and all the program's I can find seem to be much more complex.
I have been trying to do this using java swing just creating a GUI that when you press a JButton inserts a picture into a JLabel, but I'm thinking this kind of thing must be the wrong approach and there must be a better way.
Any ideas and suggestions would be much appreciated...

Java gui that allows user to move fields

I'm trying to create a java gui, currently I'm playing around in the netbeans IDE using their gui creator, but I've also been reading a book about Swing and trying to learn it that way as well. Im hoping someone can help me with a problem I'm having. I'm attempting to allow users to have a "pool" of fields they can choose from (for instance a title, a paragraph, a text fiend, buttons, etc) and be able to move items from the pool into another potion of the window which would let them create their own layout. At this point I don't need these fields to DO anything, but I do want the user to be able to move them around and create their own layout. Is there any way to do this?
I think that to do this, you'd need to use a null layout on the container that would hold the movable components, and you'd have to give the components MouseListeners and MouseMotionListeners (conveniently combined into MouseAdapters) that are active when the program is in the set-up state, but then inactive when the program's components have been all set.
You could use the DragLayout from the tips4java website.

Java SWING - How to put my functionality under my tabs?

At the Moment I am coding my GUI, but my programm functionality flows under my tabs.
Example:
Does anybody has an idea how to fix that?
Your Layout is broken.
Try to split up component-parts (tabs and the panel content below tabs).
Add only these parts and see whether the layout of those particular components is OK.
Put everything you have into a scrollable would help you to analyse the problem and see the actual required size of your components.
Try to avoid using prefferedSize/minSize/maxSize in your code, it was not meant to layout your stuff.

Java Netbeans: How to layer panels on top of each other?

Please bear with me as I've just started using NetBeans for the first time! Basically what I'm trying to do is create different panels that fit inside one frame, except that only one panel will be visible at a time. It'll start with one panel, and depending on what the user inputs, the panel that corresponds to what the user puts in pops up.
I've tried looking into utilizing LayeredPanes since that's what I've come after hours of researching this only.. I don't understand how to do it! I think using different panels would be much easier than using different frames, so that's why I'm just going to stick with layering panels.
If anyone could explain LayeredPanes, I'd be very grateful! I'm not sure my coding will help here, but if anyone needs it I'll put it up.
This tutorial should point you in the right direction, however, if you want to have items positioned over each other, you might also want to take a look at the CardLayout:
The CardLayout class manages two or more components (usually JPanel
instances) that share the same display space.
Reading your question I dont think that what you need is a LayeredPane,
Basically what I'm trying to do is create different panels that fit inside one frame, except that only one panel will be visible at a time.
Tell exactly what you want to achieve, I mean on what you are working on.
...and depending on what the user inputs, the panel that corresponds to what the user puts in pops up.
I'd like to suggest a JDialog , show dialogs depending on the user inputs. To make sure if this is what you need, you want to provide us with more information. :)

Need help with Layouts in Swing

I'm using Java Swing and I have the following problem:
I have a class TnaiPanel that extends JPanel. In this class I am creating 3 components and then lay them out in a horizontal line using a BoxLayout.
Also, I have a class TnaimDinamimPanel that also extends JPanel. This class contains multiple occurances of TnaiPanel, layed out vertically using a BoxLayout.
Also, I have a class MainFrame that extends JFrame. This frame contains a menu-bar and one main panel. The main panel can change (when choosing a certain menu-item, I create a new panel and set it to show as the main panel of the frame).
Now, for some reason I get "BoxLayout can't be shared" when I add the newly created TnaimDinamimPanel to the components of the frame.
I don't mind using different layout objects.
The result I want to get is a sort of "table" of components, where each TnaiPanel will have fixed component sizes and spacing, essentially serving the role os a "row" in the "table".
Thanks,
Malki.
You probably create only a single BoxLayout instance. Create a new one each time you need one (i.e. one per TnaiPanel, one per TnaimDinamimPanel and probably one per MainFrame).
To answer the second part of your question, ie "having a table of components", I would say that you can't do it with different panels, except if you start setting the individual min, pref and max sizes of components and panels, which is highly unadvised.
If you need to have correct alignment as in a table of components, then you need to put all your components in one panel, which also means you need to use only one layout. However, the only default swing layout that can allow you to do what you want is the GridBagLayout. Actually the GroupLayout (java 6) would also fit the bill but it absolutely requires a graphical designer (eg the one within netbeans).
If, like me, you are allergic to builders, then you'd better use one 3rd-party LayoutManager that is intended to be use programmatically (I would not consider GridBagLayout to be in this category although I have already used it that way in the past).
MigLayout (as suggested by Skeptic) is one option. Another option is DesignGridLayout which might fit your purpose better and is easier to use than MigLayout.
Try MiGLayout instead.

Categories

Resources