File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
GridBagLayout problem
miguel lisboa
Ranch Hand
Joined: Feb 08, 2004
Posts: 1281
posted
Jun 30, 2005 16:43:00
0
i'm trying to build the following:
lbl1 txt1 bt1 bt2 bt3 bt4
lbl2 txt2 bt5 bt6
but when i try to add button bt5 it allways goes right to bt4 right side!
here's my code:
import javax.swing.*; import java.awt.*; public class Test extends JFrame { static final long serialVersionUID = 2889265010042717001L; private JPanel panel; private GridBagConstraints c; public Test() { super("Editar Conven��es"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel = new JPanel(); panel.setLayout(new GridBagLayout()); c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 10); // LINHA 1 c.gridx = 0;// coluna 0 c.gridy = 0;// fila 0 c.anchor = GridBagConstraints.EAST; panel.add(new JLabel("Comparticipa��o"), c); c.gridx = 1; c.fill = GridBagConstraints.HORIZONTAL; JTextField txt1 = new JTextField(20); panel.add(txt1, c); c.gridx = 2; JButton b1 = new JButton("||<"); panel.add(b1); c.gridx = 3; panel.add(new JButton("<")); c.gridx = 4; panel.add(new JButton(">")); c.gridx = 5; panel.add(new JButton(">||")); // LINHA 2 c.gridx = 0; c.gridy = 1;// fila 1 panel.add(new JLabel("A pagar pelo Utente"), c); c.gridx = 1; c.fill = GridBagConstraints.HORIZONTAL; panel.add(new JTextField(), c); c.gridx = 2; //c.fill = GridBagConstraints.NONE; panel.add(new JButton("Actualizar")); getContentPane().add(panel); setSize(800, 140); setVisible(true); } public static void main(String args[]) { new Test(); } }
i tried several constraints variations but with no result
How can i solve this?
TiA
java amateur
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
Jun 30, 2005 17:12:00
0
panel.add(new
JButton
("Actualizar"));
panel.add(new
JButton
("Actualizar"),c);//add the constraint
miguel lisboa
Ranch Hand
Joined: Feb 08, 2004
Posts: 1281
posted
Jun 30, 2005 17:17:00
0
of course!
thanks
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: GridBagLayout problem
Similar Threads
help automate code
help on reading textfield on 1 class from another class and using it to create a file
how to set this a borderq
GridBagLayout:: a few Qs
GridBagConstraints Problem
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter