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.
Related
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
I have a fairly large (6000 lines) java application with over 40 buttons etc. and fixed window size.
This is creating problem for people who wants to use it for some it is too small for others it is too large with no scrolling! How can I retroactively make it fit different screens?
Thanks
If yours is a Swing GUI (you have not mentioned this yet)
Don't use fixed size anything.
Use layout managers and nested JPanels to do the heavy work for you.
One comment to your question mentions using GridBagLayout, but I suggest that you avoid using this, that you instead use nested JPanels that use simpler layout managers, or use MigLayout.
To fill the Screen, set the extended state appropriately: setExtendedState(JFrame.MAXIMIZE_BOTH)
I am using the NetBeans 7.2.1 GUI Builder. I could do all of this by hand. Instead, I am using my current project to learn how this tool works so that I can make an informed decision of when to use it in the futre (if at all).
Now with help of archived questions here, I have figured out how to change the LayoutManager to a CardLayout. I have also added three JPanels to the layout (although, there seems to be a bug...maybe a question about that later). The first JPanel displayed by the CardLayout will have two buttons. Each button will cause the CardLayout to display one of the other two JPanels. To do this, I found that I can use CardLayout#show(Container, String).
I need to know what the value of the String is for each JPanel. Doing some further research, I found that NetBeans generates a line of code such as
getContentPane().add(addCardsPanel, "card2");
So I can use "card2" to show addCardsPanel. It would be convenient to use a more applicable String. Will NetBeans allow me to set this identifying String to whatever value I wish? If so, how do I do it?
In the Navigator window select the panel you want.
In the Properties window scroll down to the Layout group. You'll see a Card Name property. Knock your self out ;)
Let's imagine situation where you're making the layout for a webpage. In HTML you can put the stuff in divs and use CSS to set positioning, e.g. size, positioning, etc.
Let's have another situatinon, but same requirements. You're programing in Java Swing, and you also want to make layout with similar requirements, e.g. size, positioning, etc.
I haven't found layout managers useful in this situation, because they make it one way, but never as you want it, e.g. one part will be next to another part, and it will have some size.
In short: I want the layout to handle positioning and setting sizes of GUI parts as happens with divs in HTML & CSS. I'm programing it in Java Swing.
I've tried swinghtmltemplate, but know about xito try to look through these projects, maybe you will find good solution for you. And yes, there is MiG layout
In the Java Swing app I made it seems to me that all the component are too tightly packed.
In QT one can specify padding and margins for the layout.
Is there something similar for swing?
alt text http://img12.yfrog.com/img12/9612/screenshotscreenerconfi.png
Here is a screen shot of my application that I thing is too tight (is it? what do you think?.
Thanks.
Take a look to the GridBagLayoutManager. Its the most compex layout manager but everything can be acomplished whith it.
It uses the GridBagConstraintObject which has the inset property, it specifies the separation to the top, bottom, left and right components.
example: GridBagConstraintObject.insets.left=20
You could use MiGLayout as your layout manager. It allows all kinds of customizations, including margins/paddings.
You could achieve a much better layout for the example above by using DesignGridLayout in just a couple of lines of code (one per row in your layout). DesignGridLayout will automatically use the correct spacing for the runtime platform.
besides I would highly suggest that you DON'T use TitledBorders in your form because it prevents ANY LayoutManager (as advanced as it may be) from automatically aligning correctly the various components across different groups. Instead you could use a JLabel with a JSeparator (there are examples in DesignGridLayout, but this works with any other LayoutManager).
Since Java 1.6 swing there is a new GroupLayout manager that make this kind of works easier.
For instance there is a method: setAutoCreateGaps() that:
...you add two components to a SequentialGroup a gap between the two components is automatically be created...
For instance:
What LayoutManager are you using? Adding margins is quite easy, it depends however on the specific LayoutManager used.
FormLayout is another good layout manager. With a good GUI editor like JFormDesigner it makes GUI building easy enough. JFormDesigner actually automatically adds sufficient padding in most cases. I have to recommend against using GridBagLayout. It does the job alright, but is very complex which makes it difficult to use and maintain.