Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 28-01-2010
Join Date: Nov 2009
Posts: 877
GUI arrangement in java

Hello, I am creating project in java and while starting it, But I am not able to create the arrangement of the object. If anyone is having idea from which I can able to get the solution then please help me. I have tried a lot. How can I create this GUI application? Can I make use of the GridBagLayout? Or it is needed to make use of the combination of all the layout.
Reply With Quote
Old 28-01-2010
Join Date: Apr 2008
Posts: 1,948
Re: GUI arrangement in java

Hello, when I was creating my project, I had used the JPanel with BorderLayout which would use the positions NORTH, SOUTH and CENTER and done the setting as below:
A JScrollPane (panel with bar lifts) that contain your JTextArea in the central position
a progressBar
a JPanel with a GridLayout (1 column, 2 lines) containing:
- A JPanel with a BoxLayout containing your JLabel, JTextField, JButton
- A JPanel with your JButton
Reply With Quote
Old 28-01-2010
Join Date: May 2008
Posts: 2,008
Re: GUI arrangement in java

For arranging the GUI in your code with java you must need to make use of the code below:
JFrame frm = new JFrame("AppName V0.1");
JPanel pnl = new JPanel();
pnl.setLayout(new GridLayout(1, 2); 

JPanel panel = new JPanel();
BoxLayout boxl = new BoxLayout(panel, BoxLayout.X_AXYS);
panel.add(new JLabel("Label 1"));
panel.add(new JTextField("text field"));
panel.add(new JButton("Button 1"));
pnl.add(new JButton("Button 2"));
JTextArea text = new JTextArea("Text area");
JScrollPane panelCentre = new JScrollPane(text);
JProgressBar progressbar = new JProgressBar(...);
JPanel panelPrincipal = new JPanel();
panelPrincipal.setLayout(new BorderLayout());
panelPrincipal.add(pnl, BorderLayout.NORTH);
panelPrincipal.add(panelCentre, BorderLayout.CENTER);
panelPrincipal.add(progressbar, BorderLayout.SOUTH);
Reply With Quote
Old 28-01-2010
Join Date: Apr 2008
Posts: 2,001
Re: GUI arrangement in java

Then an explanation of the components used GridBagContraints here:
  • gridy: Line number on which you place the component
  • gridx: Column number on which the component is placed
  • GridWidth: Number of cases that horizontal component will occupy from that specified in gridx
  • GridHeight: Number of vertical boxes that will hold the component from that specified in gridy (unused here)
  • fill: Politics occupancy of space in the box NONE that remains on the component itself and occupy the minimum footprint HORIZONTAL that the component occupies the entire space horizontal, vertical component holds for all vertical space, BOTH to occupy all the space
  • weightx: Policy horizontal scale of the box itself and the value is close to 1, the box will occupy more horizontal space available in the container. If the value is 0 (default) the box does not grow and occupies minimum space needed to display its
  • Weighty: Same but in vertical
  • anchor: Specifies where to place the component in the box. In our case we remain with the values BASELINE_XXX to align vertically the text of individual components on a single ligne.BASELINE_LEADING: aligns all components depending on the height of their text and places them in front of the line. BASELINE places in central and BASELINE_TRAILING end of the line.
Reply With Quote
Old 28-01-2010
Join Date: May 2008
Posts: 2,293
Re: GUI arrangement in java

Hey, see I have got the following code which will help you to get the more detail about the GUI coding :
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
Public class testing extends JFrame 
	private static Final long serialVersionUID = 1L;

	private TPointeuse tPointeuse;
	private JButton btn;
	private GridBagConstraints c;
	private JPanel panel;
	private JScrollPane scrolpane;
	private JScrollPane scrollpane;
	private JTextArea t1;
	private JTextArea t2;

testing() {
		great("testing v1.0");

btn = new JButton("OK");

t1 = new JTextArea(5, 20);

scrolpane = new JScrollPane(Comment);

t2 = new JTextArea(10, 1);

scrollpane = new JScrollPane(Console);

panel = new JPanel(new GridBagLayout());
c = new GridBagConstraints();
c.gridy = 0;
c.gridx = 0;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
panel.add(scrolpane c);
c = new GridBagConstraints();
c.gridy = 0;
c.gridx = 1;
c.fill = GridBagConstraints.VERTICAL;
panel.add(btn, c);
c = new GridBagConstraints();
c.gridy = 1;
c.gridx = 0;
c.GridWidth = 2;
c.Weighty = 1.0;
c.fill = GridBagConstraints.BOTH;
panel.add(scrollpane c);

tPointeuse = new TPointeuse(this);
	protected void writeln(String text) {
		t2.append(text + "\ n");
	Public static void hand(String[] args) {
		new testing();
Reply With Quote
Old 28-01-2010
Join Date: Oct 2005
Posts: 2,389
Re: GUI arrangement in java

If you are making use of the panel for your GRI then it is necessary to perform the following coding :
public class pnltesting extends Frame 
    public pnltesting(String str) 
	  addComponent("North", new Button("North"));
	  addComponent("South", new Button("South"));
	  addComponent("East", new Button("East"));
	  addComponent("West", new Button("West"));
	  addComponent("Center", new Button("Center"));
    public void addComponent(String location, Component cmp) 
	  Panel pnl = new Panel();
	  add(location, pnl);
    public static void main(String[] args) 
       pnltesting obj = new pnltesting("BorderPanelExample");
	obj.setSize(200, 150);
Reply With Quote

  TechArena Community > Software > Software Development
Tags: , , ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "GUI arrangement in java"
Thread Thread Starter Forum Replies Last Post
The arrangement of network EveryWer Networking & Security 5 20-10-2011 07:11 AM
Random arrangement of the red pixels to replacing the Black Ravandur Monitor & Video Cards 7 24-09-2011 08:18 AM
Pictures arrangement are not in order in ipad LynDa55 Portable Devices 3 04-01-2011 06:14 AM
Arrangement of 8x1.5TB drives in ZFS NAS Lilija Hardware Peripherals 4 22-11-2010 07:16 AM
Toolbar arrangement in Internet Explorer 8 LasitMalinga Technology & Internet 3 06-05-2009 08:19 PM

All times are GMT +5.5. The time now is 11:08 PM.