Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with layout in tabbedpanes HELP HELP java 1

Status
Not open for further replies.

tig12

Programmer
Feb 27, 2007
20
0
0
GB
Hi,
could anyone help me fix the layout on my tabbedpane.

I am using gridlayout but the components

i.e. Jbutton, Jlabel, Jtextfields, combo box and Jlist

All these are too large and I want to create a form i.e. when setting up an account can anyone help

trying to create a form

PLEASE PLEASE
 
I can't see any code ? How can we help without code examples of you problem ?
If you post reams of code, I doubt you'll get a response - so you'll need to post a succinct example which demonstrates your problem.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
You can :-

1) Disable the LayoutManager (using a null). You can place your components exactly where you want them, and with the size you want them (using setBounds). The drawback is that nothing will resize/relocate automatically when the containing panel is resized.

2) Use a variety of nested LayoutManagers. Eg. Put labels into a one column GridLayout panel and their corresponding fields into another one column GridLayout panel. Put these, respectively into the WEST and CENTER of a BorderLayout panel, and then this latter into the NORTH of a BorderLayout panel on your TabbedPane. This can get a little intricate for large numbers of components, but for reasonable numebrs you can achieve good results.

3) Use a GridBagLayout with GridBagConstraints to control the layout of the components. The GridBagLayout is an advanced LayoutManager which takes a bit of getting used to.

4) Forget Swing/AWT and switch to delivering your content via a web browser. You'd need to use JSP / Servlet or some Web MVC framework like Struts in a servlet container such as Tomcat, and then use HTML / CSS (or even AJAX) to deliver your front-end interface.



Tim
 


Cant work out how to layout, can any one help, when I try to resize or put the JComponents in specific places i.e. right of label does not work can any one help.

I have put some code up

thank you for your time









//Additional Information
public void createPage4()
{

panel4 = new JPanel();

panel4.setLayout(new GridLayout(8,8));

GridBagConstraints con = new GridBagConstraints(); // create a new constraints object




label = new JLabel("Any Additional Information:", JLabel.LEFT); // create label
con.gridwidth = 3; // set the width of the grid to 3 grids
con.gridx = 0; // places component at grid
con.gridy = 0; // reference (0,0 )
con.weightx = 0.5; // sets the weigh to 0.5
panel4.add(label);



label1 = new JLabel("Question One:", JLabel.LEFT); // create label1
con.gridwidth = 3; // set the width of the grid to 3 grids
con.gridx = 2; // places component at grid
con.gridy = 0; // reference (0,0 )
con.weightx = 0.5; // sets the weigh to 0.5
panel4.add(label1);

q = new JTextField("A Text Field");
con.gridx = 0;
con.gridy = 2;
con.gridwidth = 1; // sets the gridwidth back from 3 to 1
con.insets = new Insets(20, 20, 20, 20); // create the insets ie the spacing between components to 20 at each side
panel4.add(q, con); // adds field to the cpntainer using the specified constraints





label2 = new JLabel("Question Two:", JLabel.LEFT); // create label2
con.gridwidth = 3; // set the width of the grid to 3 grids
con.gridx = 4; // places component at grid
con.gridy = 0; // reference (0,0 )
con.weightx = 0.5; // sets the weigh to 0.5
panel4.add(label2);

q1 = new JTextField("A Text Field");
con.gridx = 0;
con.gridy = 2;
con.gridwidth = 1; // sets the gridwidth back from 3 to 1
con.insets = new Insets(20, 20, 20, 20); // create the insets ie the spacing between components to 20 at each side
panel4.add(q1, con); // adds field to the cpntainer using the specified constraints




label3 = new JLabel("Question Three:", JLabel.LEFT); // create label3
con.gridwidth = 3; // set the width of the grid to 3 grids
con.gridx = 6; // places component at grid
con.gridy = 0; // reference (0,0 )
con.weightx = 0.5; // sets the weigh to 0.5
panel4.add(label3);

q2 = new JTextField("A Text Field");
con.gridx = 0;
con.gridy = 2;
con.gridwidth = 1; // sets the gridwidth back from 3 to 1
con.insets = new Insets(20, 20, 20, 20); // create the insets ie the spacing between components to 20 at each side
panel4.add(q2, con); // adds field to the cpntainer using the specified constraints


//update1 = new JButton("Update Records"); // creates a new button component
// con.gridwidth = 3;
// con.gridx = 1;
// con.gridy = 0;
// panel4.add(update1, con); // adds button

update1 = new JButton ("Enter");
con.gridx=0;
con.gridy=3;
con.weighty=1;
panel4.add(update1, con);


}
 
GridBagConstraints only work with the GridBagLayout. The GridLayout is a much simpler beast and lays out the components evenly in the panel space.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top