• Post Reply Bookmark Topic Watch Topic
  • New Topic

Swings Problem!!!!  RSS feed

 
Himanshu Rawat
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This problem have been bugging me for last 1.5 days. The problem is like this.

I have a main window Frame and over that i m displaying a JTabbedPane. One of its tab have some labels,combo boxes and text fields. This JTabbedPane extends JPanel. So a panel containg JTabbedPane is displayed over a frame.This i have done but when i am maximizing and minimizing the window then position of labels,combo boxes and text fields is not changing with respect to main frame???

Please tell me how to do it!!!
 
shansi raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use gridbag layout. i tried just now...its working fine
 
Himanshu Rawat
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please give me the code..just for looking..cos it isnt working on my side...
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to remember that unlike C#, Java has lots of layout managers. You don't usually specify how many pixels you want a component to be, you let the layout manager sort that out for you.
If you set the layout manager to null rather than the defaults for each component (eg JFrame defaults to Border and JPanel defaults to Flow), then you have to set the exact location and size of every object shown (setBounds() is a quick way to do it). But once you have set the size, reducing the size of the enclosing JFrame will cause some of the components to disappear off the edge of the windiw.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posted by Shansi Raj
Use gridbag layout.
Agree.

But have a look at this website of Cay Horstmann's. It has a useful class which makes handling GridBag quicker and easier.
 
Himanshu Rawat
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell,

Exactly!! I have set layout to null. To change the position i have written some code that works but not fully . I was thinking that there may be some easier way of doin it???
Campbell should i make Main frame window layout ->> gridBag or Jpanel layout->> gridbag???
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While gridbag layout is nice, it has it's own share of problems. As Campbell said, there are many layout managers for Swing. The good ones aren't even part of the core API.

See This for a chuckle. And then you might want to check out some other layout managers like JGoodies Forms. Do a google search as well and see what else is out there.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!