Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2005

Tip: Looking for answers? Try searching our database.

A 'greedy' component...

Thread view: 
Rob McDonald - 31 Oct 2005 16:12 GMT
I have developed a graphical interface extended from java.awt.Component.  It
is drawn using Graphics2D objects, and is nicely interactive.

When the interface is placed in a JPanel, which is placed in a JFrame,
everything works great.  My interface checks the its size, and calculates
the size & placement of all the internal stuff.

However, when you try to put anything else in the JFrame or JPanel, my
component gets shrunk to a point, and isn't displayed.

How can I make a component's default behavior to be to expand to fill all
available space?

Component.setPreferredSize(new Dimension(Integer.MAX_VALUE,
Integer.MAX_VALUE));

Any suggestions are appreciated,

        Rob
Chris Smith - 31 Oct 2005 16:29 GMT
> I have developed a graphical interface extended from java.awt.Component.  It
> is drawn using Graphics2D objects, and is nicely interactive.
[quoted text clipped - 8 lines]
> How can I make a component's default behavior to be to expand to fill all
> available space?

This isn't about the component, but rather about the layout manager in
the container.  What layout manager are you using for the JFrame's
content pane?  How about for the JPanel?

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Rob McDonald - 31 Oct 2005 16:38 GMT
> This isn't about the component, but rather about the layout manager in
> the container.  What layout manager are you using for the JFrame's
> content pane?  How about for the JPanel?

I do something like this...

final JFrame frame = new JFrame("My Frame");
final JPanel mainPane = new JPanel();
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.PAGE_AXIS));
frame.getContentPane().add(mainPane, BorderLayout.CENTER);

MyComponent myComp = new MyComponent();
mainPane.add(myComp);
JTextField textF = new JTextField(10);
mainPane.add(textF);

And I get a giant JTextField, with a non-existant MyComponent.  If I force
the textF.setSize(100,15); I get a small JTextField, and a speck that I
assume is supposed to be the MyComponent.

I also tried a FlowLayout() instead of the BoxLayout(), without any
significant change in behavior.

          Rob
Andrey Kuznetsov - 31 Oct 2005 16:46 GMT
> I also tried a FlowLayout() instead of the BoxLayout(), without any
> significant change in behavior.

try BorderLayout

Signature

Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Andrey Kuznetsov - 31 Oct 2005 16:44 GMT
> When the interface is placed in a JPanel, which is placed in a JFrame,
> everything works great.  My interface checks the its size, and calculates
> the size & placement of all the internal stuff.

your interface should also tell his parent his preferred size (*not*
Integer.MAX_VALUE!)
see
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html#getPreferredSize()

Signature

Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.