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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
how to center this button 1
Roldan Baldo
Ranch Hand
Posts: 99
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
how to center button 1 please? what code will i add.
import java.awt.*; import javax.swing.*; class Test{ public static void main(String args[]){ new width(); } static class width extends JFrame{ width(){ super("Frame"); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); JButton button1 = new JButton("button 1"); JButton button2 = new JButton("button 2"); JButton button3 = new JButton("button 3"); c.gridwidth = 3; c.gridx = 0; c.gridy = 0; panel.add(button1,c); c.gridwidth = 1; c.gridx = 0; c.gridy = 1; panel.add(button2,c); c.gridx = 1; c.gridy = 1; panel.add(button3,c); this.add(panel); this.setSize(300,300); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } }
Rob Spoor
Sheriff
Posts: 22783
131
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Button 1 already is centered when I
test
your code. And it should - the anchor property of GridBagContraints defaults to centered.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
size of one button is less than expected in GridBagLayout
JFrame problem
GridBagLayout problem
GridBagLayout...!
help automate code
More...