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 / September 2006

Tip: Looking for answers? Try searching our database.

panel size vs. frame size

Thread view: 
atilagunes@gmail.com - 26 Sep 2006 09:20 GMT
Hi,

i'm writing a gui that has a main panel and includes 3 subpanels.. and
has a Menu Bar..

i'm setting size of Frame with
GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()
function.

My screen Size is 1280 * 800 and because of Start button, it takes 1280
* 770.. its ok so far.
you know the JFrame has a title bar. and suppose that i add a MenuBar
to that JFrame. how can i measure the best size of main Panel and its
bounds. i'm using null layout in main Panel and force the subpanels to
main Panel but the X and Y values are not true.  i think it shifts to
down because of title bar and menu bar. i'm trying several boundaries
for subpanels but i could not fit them onto main panel..

i hope this message can be understood..

Regards
Atila Gunes.
atilagunes@gmail.com - 26 Sep 2006 09:30 GMT
and also we should calculate frame border size to find best main panel
size..
Andrew Thompson - 26 Sep 2006 09:30 GMT
//
> i'm writing a gui that has a main panel and includes 3 subpanels.. and
> has a Menu Bar..
[quoted text clipped - 8 lines]
> to that JFrame. how can i measure the best size of main Panel and its
> bounds. i'm using null layout

*
>... in main Panel and force the subpanels to
> main Panel but the X and Y values are not true.  i think it shifts to
> down because of title bar and menu bar. i'm trying several boundaries
> for subpanels but i could not fit them onto main panel..

* Learn how to use layouts, and the problems should be fixed.

Andrew T.
atilagunes@gmail.com - 26 Sep 2006 09:35 GMT
i'm asking these coz two jPanel must be fix and the remain jPanel must
takes its bound according to others while jFrame size is changing.

all standart layouts except box and gridbag are meaningless for me..
Bart Cremers - 26 Sep 2006 10:01 GMT
> i'm asking these coz two jPanel must be fix and the remain jPanel must
> takes its bound according to others while jFrame size is changing.
>
> all standart layouts except box and gridbag are meaningless for me..

Working with a null layout in respect to resizable containers is just a
pain. I'm pretty sure you can get pretty far with the standard layout
managers. Post an example of the required output (ascii drawing?) and
it might be easier to understand your goal. If for some reason it
really is not possible to get to what you want using the standard
layout managers, there's always the option to write your own custom
layout manager.

Regards,

Bart
Andrew Thompson - 26 Sep 2006 10:24 GMT
> i'm asking these coz two jPanel must be fix and the remain jPanel must
> takes its bound according to others while jFrame size is changing.

Sounds like it mght be well suited to a nested layout,
or perhaps a single BorderLayout.

Put the component that you want to resize into
BorderLayout.CENTER, then if the other components
can go 'around it', try BorderLayout.EAST and WEST
or BorderLayout.NORTH and SOUTH.

If you need both the fixed components on one side,
put them in a JPanel with an appropraite layout, then
add the JPanel to the main BorderLayout (in any one
of NORTH/EAST/WEST/SOUTH).

> all standart layouts except box and gridbag are meaningless for me..

You need to play with them till they have a meaning.

It is very hard to layout GUI's without some understanding
of a number of layouts, as well as the idea of nested layouts
(putting a panel with a different layout, inside a larger layout).

Andrew T.
atilagunes@gmail.com - 26 Sep 2006 10:41 GMT
thanks for answers... actually, i give up to use layout when i dont see
good results but here it works well..

Regards
Atila Gunes
Thomas Weidenfeller - 26 Sep 2006 10:11 GMT
> suppose that i add a MenuBar
> to that JFrame. how can i measure the best size of main Panel and its
> bounds. i'm using null layout in main Panel

Don't do that. Use a layout manager and let it figure out the available
remaining space. That's what they are for.

/Thomas

Signature

The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

Ian Wilson - 26 Sep 2006 10:43 GMT
> Hi,
>
[quoted text clipped - 15 lines]
>
> i hope this message can be understood..

Use layouts, they make this sort of thing easy.

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

public class TriBox {
    public static void main(String[] args) {
        JFrame frame = new JFrame();

        JPanel p1 = new JPanel();
        p1.add(new JLabel("Panel 1: height fixed at 200 pixels"));
        int width = (int)p1.getPreferredSize().getWidth();
        p1.setPreferredSize(new Dimension(width ,200));
        p1.setBorder(new TitledBorder("1"));

        JPanel p2 = new JPanel();
        p2.add(new JLabel("Panel 2: height fixed at 100 pixels"));
        width = (int)p2.getPreferredSize().getWidth();
        p2.setPreferredSize(new Dimension(width ,100));
        p2.setBorder(new TitledBorder("2"));

        JPanel p3 = new JPanel();
        p3.add(new JLabel("Panel 3: variable height"));
        p3.setBorder(new TitledBorder("3"));

        JPanel fixedPanel = new JPanel();
        fixedPanel.setLayout(
                new BoxLayout(fixedPanel, BoxLayout.PAGE_AXIS));
        fixedPanel.add(p1);
        fixedPanel.add(p2);

        frame.setLayout(new BorderLayout());
        frame.add(fixedPanel, BorderLayout.NORTH);
        frame.add(p3, BorderLayout.CENTER);

        frame.pack();
        frame.setVisible(true);

    }
}
atilagunes@gmail.com - 26 Sep 2006 12:14 GMT
thank you for this great example..


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.