473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Uniform size in components added using GridBagLayoutManager

118 100+
Hie , I am adding three buttons to my frame but when I am running the code , the buttons do not have uniform width. Can someone help me out.- I need ideas on how to make btnA,btnB and btnC have the same width. The code is not giving errors when I run it. The code is

NB: My class extends JFrame

Expand|Select|Wrap|Line Numbers
  1.  
  2. Container cont=getContentPane();
  3.         JPanel panel=new JPanel(new GridBagLayout());
  4.         GridBagConstraints gbc= new GridBagConstraints();
  5.         gbc.weighty=0.5;
  6.         //gbc.fill=GridBagConstraints.HORIZONTAL;
  7.         gbc.weightx=0.5;
  8.         gbc.gridx=0;
  9.         gbc.gridy=0;
  10.         btnA=new JButton("AAAAA   AAAAA");
  11.         panel.add(btnA,gbc);
  12.         gbc.gridy=1;
  13.         btnB = new JButton("BBBB BBBBBBBBB");
  14.         gbc.gridy=2;
  15.         panel.add(B,gbc);
  16.         btnC=new JButton("CCCCCCCCC");
  17.         gbc.gridy=3; 
  18.         panel.add(btnC,gbc);       
  19.         setSize(300,200);          
  20.           cont.add(panel);
  21.           setVisible(true);
  22.           setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  23.  
  24.  
Nov 23 '07 #1
5 2120
JosAH
11,448 Expert 8TB
If you really want them to be the same size use a GridLayout instead;
specify one single row and your buttons end up next to each other, all of the
same size.

kind regards,

Jos
Nov 23 '07 #2
heat84
118 100+
If you really want them to be the same size use a GridLayout instead;
specify one single row and your buttons end up next to each other, all of the
same size.

kind regards,

Jos
Thanks-
The buttons are arranged vertically so I want them to have the same width but not height. However , if there is no way of manouvering except changing the layout manager to GridBagLayout , then I will settle for that.
Nov 23 '07 #3
heat84
118 100+
If you really want them to be the same size use a GridLayout instead;
specify one single row and your buttons end up next to each other, all of the
same size.

kind regards,

Jos
Thanks-
The buttons are arranged vertically so I want them to have the same width,the height is not a problem to me. However , if there is no way of manouvering except changing the layout manager to GridLayout , then I will settle for that.
Nov 23 '07 #4
JosAH
11,448 Expert 8TB
Thanks-
The buttons are arranged vertically so I want them to have the same width,the height is not a problem to me. However , if there is no way of manouvering except changing the layout manager to GridLayout , then I will settle for that.
A GridLayout can also arange components vertically: for your three buttons
specify three rows in the GridLayout.

kind regards,

Jos
Nov 23 '07 #5
heat84
118 100+
A GridLayout can also arange components vertically: for your three buttons
specify three rows in the GridLayout.

kind regards,

Jos
Thank you Jos , you can now proceed with fighting the politicians .
Nov 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mario T. Lanza | last post by:
Greetings, I don't know about you guys but on many occasions I've asked myself whether or not someone else has solved a particular programming issue -- whether or not they developed a clever...
1
by: Robert Oschler | last post by:
Is there a Javascript function, or library, that will take a URL and make it uniform/consistent? Something that will resolve all relative pathing and the current domain and protocol and return a...
9
by: lauren quantrell | last post by:
Is there a way to determine the size of the user's screen minus the Windows task bar? I am trying to maximize an Access popup form that is also resizeable and it is causing me problems since it...
5
by: marcosegurini | last post by:
Hi, the following class describes my actual problem: class DeepCopy<T> { T val_; public void Assign(T newVal) {
12
by: J L | last post by:
When I fill a listview, I resize the columns to fit the data. I need to know if the data will fit vertically or if there will be a vertical scroll bar. I need to know this so I can allow for it on...
5
by: Jerry | last post by:
In ASP (pre .NET) I referenced components by MyObj = Server.CreateObject("DllName.Classname") In .NET, I know that to reference the Sql namespace I use <%@ Import...
38
by: JTL | last post by:
I have learnt java before and now begin to learn c++ what puzzle me is that seem that different SDKs(c++builder, vs.net, gcc..) has its own class library we know that in java there are only one...
8
by: kiranchahar | last post by:
Hey all, How do I generate random numbers with Uniform distribution Uniform(a,b) using C-programming? I want to generate uniform random numbers which have mean following Uniform(p,q) and also...
25
by: tooru honda | last post by:
Hi, I have read the source code of the built-in random module, random.py. After also reading Wiki article on Knuth Shuffle algorithm, I wonder if the shuffle method implemented in random.py...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.