fill | allows the components to resize automatically when the row or column expanded or thrinked. |
---|---|
gridwidth | specifies the number of columns in the area to display the component. |
gridheight | specifies the number of rows in the area to display the component. |
gridx | specifies the column in the grid to display the component. Its value starts from 0 (first column). |
gridy | specifies the row in the grid to display the component. Its value starts from 0 (first row). |
Example: The following code below arranges the components on the JFrame window as shown in the picture.
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class GridBagLayoutManager {
public static void main(String[] args){
JFrame jf=new JFrame("GridBagLayout");
jf.setSize(500,300);
Container container=jf.getContentPane();
GridBagLayout gb=new GridBagLayout();
container.setLayout(gb);
GridBagConstraints gc = new GridBagConstraints();
JButton bt1=new JButton("Button 1");
JButton bt2=new JButton("Button 2");
//fill components in cells
gc.fill = GridBagConstraints.BOTH;
gb.setConstraints(bt1, gc);
gc.gridwidth = GridBagConstraints.REMAINDER;
gb.setConstraints(bt2, gc);
container.add(bt1);
container.add(bt2);
//add JTextArea, Button 3, and Button 4 to the second row
JTextArea ja=new JTextArea(10,10);
ja.setLineWrap(true);
ja.setText("GridBagLayout is a layout manager that is more powerful than the GridLayout manager.");
JButton bt3=new JButton("Button 3");
JButton bt4=new JButton("Button 4");
//expand row and column
gc.gridwidth =2; //2 columns
gc.gridheight =3;//3 rows
gb.setConstraints(ja, gc);
gc.gridwidth = GridBagConstraints.REMAINDER;
//reset row and column
gc.gridwidth =1;
gc.gridheight = 1;
gb.setConstraints(bt3, gc);
gc.gridy=2; //Add the Button 4 below the Button 3
gb.setConstraints(bt4, gc);
container.add(ja);
container.add(bt3);
container.add(bt4);
jf.setVisible(true);
}
}
If you have example with table, I prefer.
ReplyDeleteThe article is too good and it will be helpful for java developers.Thanks for sharing such useful information.
ReplyDeleteJava training in Chennai
The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
ReplyDeleteDigital Marketing Course in Chennai
Digital Marketing Training in Chennai
Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
ReplyDeleteccna Training center in Chennai
Best CCNA Training Institute in Chennai
ccna certification in Chennai
ccna course in Chennai
German Language Course in Chennai
German Courses in Chennai
Very interesting content which helps me to get the indepth knowledge about the technology. To know more detils about the course visit this website.
ReplyDeleteQtp training in Chennai
Big Data Training in Chennai
Hadoop Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Training in Chennai
JAVA Training in Chennai
Java classes in chennai
I read your blog regularly from the beginning. It was very impressed to me and I learn huge of information from your blog. Thank you!!!
ReplyDeleteEthical Hacking Course in Chennai
Hacking Course in Chennai
Certified Ethical Hacking Course in Chennai
Ethical Hacking Training in Chennai
I was in search of this blog for a while and just now got this into my vision. Thanks for sharing.
ReplyDeleteSpoken English Classes in OMR Chennai
Spoken English Classes in Perungudi
Spoken English Classes in Velachery
Spoken English Classes in Medavakkam
Spoken English Classes in Tambaram
Spoken English Class in Chrompet
Spoken English Class in Ambattur
Spoken English Classes in Ambattur OT
This information is impressive; I am inspired with your post. Keep posting like this, This is very useful.Thank you so much. Waiting for more blogs like this.
ReplyDeleteAviation Academy in Chennai
Aviation Courses in Chennai
aviation institute in chennai
best aviation academy in chennai
Thank you so much for providing information on this. It was very useful.
ReplyDeleteair hostess training in Bangalore
air hostess academy Bangalore
air hostess academy
air hostess training institute
In the beginning, I would like to thank you much about this great post. Its very useful and helpful for anyone looking for tips. I like your writing style and I hope you will keep doing this good working.
ReplyDeleteSoftware testing training in chennai
Salesforce Training in Chennai
Big Data Training in Chennai
Hadoop Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Training in Chennai
JAVA Training in Chennai
Best selenium training in chennai
Excellent Blog!!! Such an interesting blog with clear vision, this will definitely help for beginner to make them update.
ReplyDeleteData Science Course in Chennai
Data Science Training in Chennai
SEO Course in Chennai
RPA Classes in Chennai
CCNA Training in Chennai
Data Science Training in T Nagar
Data Science Training in Tambaram
the article is awesome and verymuch helpful for my study.keep sharing more like this.
ReplyDeleteRPA Training in Chennai | Robotics Process Automation Training in Chennai | RPA course in Chennai
Blue Prism Training in Chennai | Blue Prism Training Institute in Chennai | RPA Training in OMR | RPA Training in Porur
You gave your ideas in an effective way which will reach the readers more and it will impact the others wrong thoughts.thanks for giving the commenting opportunity.
ReplyDeleteSoftware testing training in chennai
Salesforce Training in Chennai
German Classes in Chennai
mobile application development training in chennai
ios training in OMR
ios training in porur
Greetings from Carolina! I'm bored at work so I decided to check out your blog on my iphone during lunch break. I really like the knowledge you provide here and can't wait to take a look when I get home. I'm surprised at how quick your blog loaded on my phone .. I'm not even using WIFI, just 3G .. Anyways, very good blog! clear bra ny
ReplyDeleteThank you, I've just been searching for information approximately this topic for a while and yours is the best I have discovered till now. But, what concerning the conclusion? Are you positive concerning the source?best thing for cellulite on thighs
ReplyDeleteMy programmer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he's tryiong none the less. I've been using WordPress on several websites for about a year and am nervous about switching to another platform. I have heard fantastic things about blogengine.net. Is there a way I can transfer all my wordpress posts into it? Any help would be really appreciated!womens toe post sandals
ReplyDeletePlease let me know if you're looking for a author for your blog. You have some really good articles and I think I would be a good asset. If you ever want to take some of the load off, I'd love to write some articles for your blog in exchange for a link back to mine. Please shoot me an email if interested. Kudos! engage with followers
ReplyDeleteDevOps Training in Chennai
ReplyDeleteI am glad that I have visited this blog. Really helpful, eagerly waiting for more updates.
Great Article. Thank you for sharing! Really an awesome post for every one.
ReplyDeleteIEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.
JavaScript Training in Chennai
JavaScript Training in Chennai
I was in search of this blog for a while and just now got this into my vision. Thanks for sharing
ReplyDeleteExcellent Blog!!! Such an interesting blog with clear vision, this will definitely help for beginner to make them update.
ReplyDeleteC C++ Training in Chennai
ReplyDeleteExcellent blog with lots of information. I have to thank for this. Do share more.
Ethical Hacking Course in Chennai
ReplyDeleteI am glad that I have visited this blog. Really helpful, eagerly waiting for more updates.
Awesome Blog and informative content...Waiting for the next update...
ReplyDeleteDrupal Training in Chennai
Drupal 8 Training
Drupal Classes
Drupal Training in Velachery
Drupal Training in Tambaram
Photoshop Classes in Chennai
clinical sas training in chennai
SAS Training in Chennai
javascript training in chennai
Hibernate Training in Chennai
Nice Blog...Thanks for sharing the article waiting for next update...
ReplyDeleteArtificial Intelligence Course in Chennai
AI Training in chennai
ai courses in chennai
Mobile Testing Training in Chennai
C C++ Training in Chennai
javascript training in chennai
Html5 Training in Chennai
QTP Training in Chennai
Spring Training in Chennai
LoadRunner Training in Chennai
It's very useful blog post with inforamtive and insightful content and i had good experience with this information.I have gone through CRS Info Solutions Home which really nice. Learn more details About Us of CRS info solutions. Here you can see the Courses CRS Info Solutions full list. Find Student Registration page and register now.Find this real time DevOps Training and great teaching. Join now on Selenium Training online course. Upskill career with Tableau training by crs info solutions. Latest trending course is Salesforce Lightning training with excellent jobs.
ReplyDeleteAll are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information..put somemore info.i may help us.
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
nice blog..valuable information....thanks for sharing...
ReplyDeleteStudy Abroad Consultants in Kerala
study abroad consultants in thrissur
Study Abroad Consultants in Calicut
abroad job consultancy in coimbatore
best overseas education consultants in thrissur
overseas education consultants in kozhikode
study abroad
study in poland
study in europe
free abroad study
Python Training in Chennaii
ReplyDeleteThe information given in this blog is very nice and i like it if you share more this kind of blog and i also have written this kind of blog you can also read for more knowledge.
gmat coaching institutes in chennai
ReplyDeleteHaving a good score in GMAT is very important to get into your dream university. Choose the best GMAT coaching centres in Chennai from the list.
angularjs interview questions and answers for experienced
ReplyDeleteImportant AngularJS Interview Questions and Answers for freshers and experienced to get your dream job in Angular! Basic & Advanced AngularJS Interview Questions for Freshers & Experienced.
javascript interview questions and answers pdf
ReplyDeleteImportant Javascript Interview Questions and Answers for freshers and experienced to get your dream job & Advanced Javascript Interview Questions for Freshers & Experienced.
Great experience for me by reading this blog. Thank you for the wonderful article.
ReplyDeleteandroid interview questions for experienced
android basic questions
android basic interview questions
android interview question answer
rpa interview questions and answers for experienced
angularjs interview questions
angularjs interview questions and answers for experienced
php interview questions and answers
This blog is really nice and informative blog, The explanation given is really comprehensive and informative.
ReplyDeletephp interview questions and answers
php interview questions for freshers
php interview questions for experienced
php basic interview questions
rpa interview questions and answers for experienced
angularjs interview questions
angularjs interview questions and answers for experienced
php interview questions and answers
This is good site and nice point of view.I learnt lots of useful information.
ReplyDeletebig data hadoop interview questions and answers
hadoop interview questions and answers for freshers
interview questions on pega
aws interview questions and answers for devops
aws interview questions and answers for freshers pdf
python interview questions and answers for experienced
data science interview questions and answers for experienced
Excellent blog, good to see someone is posting quality information. Thanks for sharing this useful information. Keep up the good work.
ReplyDeletephp interview questions for freshers
php interview questions for experienced
php basic interview questions
software testing interview questions and answers pdf
rpa interview questions and answers pdf
rpa interview questions and answers for experienced
php interview questions and answers
php interview questions for freshers
software testing interview question and answer
Nice blog was really feeling good to read it. Thanks for this information.
ReplyDeletenetworking interview questions and answers
rpa interview questions and answers for experienced
nodejs interview questions
nodejs interview questions and answers
networking interview questions and answers
networking interview questions and answers pdf
ethical hacking interview questions
This blog is really nice and informative blog, The explanation given is really comprehensive and informative.
ReplyDeleterpa interview questions
rpa interview questions and answers
rpa interview questions and answers pdf
rpa interview questions and answers for experienced
php interview questions and answers
php interview questions for freshers
software testing interview question and answer
The information given in this blog is very nice and i like it if you share more this kind of blog and i also have written this kind of blog you can also read for more knowledge.
ReplyDeletephp interview questions and answers
php technical interview questions
php interview questions and answers for experienced
rpa interview questions and answers pdf
rpa interview questions and answers for experienced
ethical hacking interview questions
ethical hacking interview questions and answers
javascript interview questions
Thanks for your awesome post!!! I am reading your blog regularly. I like so much and i want addition info from your post.
ReplyDeletecyber security interview questions
interview questions on cyber security
cyber security interview questions pdf
cyber security interview questions for freshers
rpa interview questions and answers for experienced
angularjs interview questions
angularjs interview questions and answers for experienced
php interview questions and answers