I have been working on my assignment and I need a help regarding which layout to choose while designing the label combo box and buttons using java GUI. I want things to be done in a particular manner where in one horizontal line I need labels followed by combo box followed by button in second horizontal line I want the same things with one extra button and so on for third and fourth horizontal line. Actually my concern is that I am very much new to GUI and I need a suggestion which layout to choose and how to implement it
thanks in advance
I would go with GroupLayout (use NetBeans, it has a very good GUI builder, that makes UI creation easy). If you want to try more sophisticated solution, you may check JGoodies or MigLayout.
Related
I'm not very experienced with Java Swing Layouts. I'd like to make a layout looking like the one in the picture. Is there any easy way to understand and create layouts?
There are tutorials on the oracle website and there are wysiwyg layout-building tools that show you interactively what you are building. One of them I have personally used in the past is the Window Builder you can get as an eclipse plugin but it is by no means the only one.
In the end though what it comes down to is experience. Fool around with them, try them out, get to know them. If you dont code with them yourself it is difficult to understand them properly.
Is there any easy way to understand and create layouts?
I cannot judge what others would find easy, but my approach to laying out containers is to look for sub-sections of the GUI that would be easily done with a particular layout, then working outwards from that.
For example, it seems a single row GridLayout might be well suited to displaying the top two text panes. Then the rest of the GUI can be created by placing the panel with the two text panes into the PAGE_START constraint of a BorderLayout, with the third text pane in the CENTER and the text field in the PAGE_END.
Done.
I am creating an RAP application in JAVA.
i want to have a GUI like master detail. in which left side has panel that has a tree (like in windows 7) and on the right side there will be text fields which will be changing when different TreeItem is selected.
So i have to add two panels, but i don't know how to add panels into composite.
Please help
use frame.getContentPane() to the the master contentpane. Set its layout as new GridLayout(1,2).
Now create two panels and add them to the frame. http://docs.oracle.com/javase/tutorial/uiswing/components/panel.html
There are also more complex solutions depending on what you want to do. For example if you want to make the division of the space between left and right side cosumizable use jsplitpanes (http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html).
SWT is one thing, Swing is another. If you already have something written in SWT and want to add Swing components, then you have to use the SWT/AWT Bridge. You can find a tutorial on how to do this here.
In C#, to make the tabs go from right to left, I set RightToLeft to Yes and RightToLeftFormat to true. How do I do the same thing in Java? How do I set a JTabbedPane's tabs to display from right to left? Please see the image link below to see what I mean by displaying tabs right to left.
http://lh4.ggpht.com/_1bcR6vegNNc/TPDRekNVqWI/AAAAAAAAAB8/TwCqgajEuoI/s640/AdminDashboard.jpg
I assume by "tabbed pane" you are referring to javax.swing.JTabbedPane.
To answer your question: AFAIK there is no easy way to do what you want. The BasicTabbedPaneUI(or the TabbedPaneUI which is defined by your application look and feel) which is responsible for painting the tab area of the tabbed pane would require some changes to be able to do what you need.
If you do not have the time to write your own UI, you could look for solutions in the web. I doubt that there would be a ready to use solution to your question though, but then again, who knows?
Hope this helps you a bit.
Then i'm refer from "How to Use Tabbed Panes" to create a new project based by JTabbedPane component...
It's enough to use "setComponentOrientation" method to change orentation of JTabbedPane.
link text
I am creating a game using java, and I'm not quite understanding how to lay out buttons in windows.
I wants seven columns of buttons, 10 high. Each button showing a single digit number, or grayed out. jbutton buttons[] 0-70
To the right, three squares that can show a red X (strikes) that remain visable while empty. I also need a 'Go' button and a 'Clear' button. I was thinking about the strikes in a horizontal arrangement, but very flexable on final design.
The only things defigned are the jbuttons that will hold the numbers, the rest can be built upon any advice received here.
I'm not just looking for an answer, I want to understand how it came to be. PLEASE OVERexplain how.
The Java tutorials have a very thorough chapter on layout managers. Read through it. ANd keep in mind: layout managers are meant to be combined.
For your 7x10 buttons, you definitely want to use a GridLayout. For the overall layout, you could use a BorderLayout with the grid taking up its center spaces, and the other control could go in its other spaces.
I assume you're using Swing, in which case take a look at this GridBagLayout tutorial.
Use Layout Managers. Make multiple JPanels and set an appropriate manager for each. Sounds like you need a GridLayout.
I have a JFrame in which i have to insert JLabels, textfields and JButtons. I am able to these but how can i adjust them to the required position, i want to add one label and textfield in one row and then nxt label and textfield in the next row but they are coming in the same horizontal line. i have used flowLayout with the JFrame. please tell me how to adjust them accordingly. thanks
The key to distributing components in a Container in Swing is the Layout Manager. There are various types out there. To do what you are looking for, you might want to consider the GridLayout. It is pretty easy to set up. You first need to create the layout. The following will create a two columned layout with as many rows as you provide:
GridLayout gl = new GridLayout(0,2);
Then you apply it to your panel:
JPanel panel = new JPanel(gl);
Then you add your items:
panel.add(textfield1);
panel.add(button1);
panel.add(textfield2);
panel.add(button2);
The GridLayout will handle moving from row to row after you fill in the columns with components.
had a look at gridbaglayout? Should serve your purpose.
A GridLayout may be what you want, or a combination of a GridLayout and a FlowLayout. Look at the LayoutManager tutorial to get a better idea of when and how to use and combine the various layout managers.
You need to study the various types of layouts swing provides.
Also you can have a look at FormLayout,provide by JGoodies. I prefer to use this than swing layouts as i find it easy to code and less lines of code
You are using the default Swing Layout Manager. If you want different behaviour (which is very reasonable) then you need to use another LayoutManager. Several exists both from Sun and "out there".
In order for you to be able to choose, you need to know how they work. I can strongly recommend using the Java Tutorial for this:
http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
Let us know if you need more than provided by e.g. nested BorderLayout's or TableLayout.
If you want to be able to position the UI elements in your application (nearly) absolutely, consider using a decent GUI builder like Matisse in NetBeans or Swing UI Designer in IntelliJ IDEA.