Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Tim Cooke
Devaka Cooray
Sheriffs:
Liutauras Vilda
paul wheaton
Rob Spoor
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Piet Souris
Mikalai Zaikin
Bartenders:
Carey Brown
Roland Mueller
Forum:
Swing / AWT / SWT
GridBagLayout problem
miguel lisboa
Ranch Hand
Posts: 1282
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 4632
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
panel.add(new JButton("Actualizar"));
panel.add(new JButton("Actualizar"),c);//add the constraint
miguel lisboa
Ranch Hand
Posts: 1282
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
of course!
thanks
java amateur
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
how to set this a borderq
GridBagLayout:: a few Qs
help on reading textfield on 1 class from another class and using it to create a file
GridBagConstraints Problem
help automate code
More...