Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Components are visible in the middle of the panel on using GridBagLayout  RSS feed

 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used GridbagLayout for setting my component in the JPanel but all the components are assembling or visible only in the mid of the Panel as soon as I use the GridBagLayout. I am attaching a code sample -




I only want to use GridBagLayout
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set the constraint's weightx and weighty
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you plan on using GridBagLayout you should also use GridBagConstraints. That's what Michael meant with constraint.
 
Campbell Ritchie
Sheriff
Posts: 53773
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Find a copy of Horstmann and Cornell (vol I) and look for their "GBC" class, which extends GridBagConstraints, and makes using GridBag much easier. There is a little about it on Horstmann's website.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's located here.
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with GridConstants but ouput did not change



 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
buntha Choudhary wrote:I tried with GridConstants but ouput did not change

GridConstants?

You need to explain the difference between your achievement and expectations. Other code comments:
1. Don't post extraneous stuff. JTabbedPane has nothing whatsoever to do with the problem.
2. Do your reades the courtesy of removing inane IDE-generated comments like // TODO Auto-generated method stub and empty javadoc
3. Also remove multiple blank lines.
4. You set the JFrame's layout to CardLayout and then add the panel with a constraint of BorderLayout.NORTH. Doesn't make sense, that.
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Darryl Burke .

It will be GridBagConstraints, sorry for the wrong word I used.

The above piece of code is just a Dummy Code.
Actually I need to create a new modules in a Product already available in the market but I did not want to add that piece of code here.
JTabbedPane is important here as I need to make in that way .
Next time onwards, I will take care for not providing the IDE generated comments and multiple blank lines.
You set the JFrame's layout to CardLayout and then add the panel with a constraint of BorderLayout.NORTH

My Mistake will rectify it.

Mt total concern was to know the proper use of GridBagLayout with JTabbedPane. I already gone through Sun Tutorials .
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
buntha Choudhary wrote:The above piece of code is just a Dummy Code.

Either PostRealCode or post an SSCCE.

JTabbedPane is important here as I need to make in that way .

The JTabbedPane is irrelevant for this specific problem. If it works for a JPanel directly in a JFrame then it will work for a JPanel in a JTabbedPane, as long as the JPanel is laid out similarly (which is the case with JFrame and JTabbedPane -- stretched).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!