Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (763)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (852)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  setSize Bug or Feature in Frame class since 1.4?  (Read 2782 times)
0 Members and 1 Guest are viewing this topic.
Offline MGodehardt

Junior Devvie




why does the chicken cross the road?


« Posted 2007-12-06 14:06:00 »

I have a application/applet which is creating Frame's of differnt size, some are 900 x 700 ( client size ), so they are a little bit bigger with the insets.

Problem is when the screen size is set to 800 x 600.

In my program as a application running under java 1.6.0_03 ( latest stable version available ) its running fine and creating a Frame of size 812 x 612 ( this is ok windows XP restricts frame to this size ).

When i run my program as a applet under MSIE 6.0 using java 1.6.0_03 as a plugin, the size of the Frame is the ScreenSize minus Screen Insets. setSize is not able to make my Frame bigger.

My Frame is resizable, when the user is making it bigger by dragging at the frame edges, the frame is resizing to 812 x 612

This is a strange and unwanted behaviour, is this a bug or a feature, any workaround known.

This strange behaviour does not happen with java 1.1 or with M$ java 1.1.4

I notice this strange frame behaviour in applets since version 1.4
Offline broumbroum

Junior Devvie





« Reply #1 - Posted 2007-12-06 14:49:08 »

Yes, this issue is well known, because the previous buffer sometimes overlaps with the new sized buffer. I recommend you to make resizing disabled but to change the resolution within a new instance of your Frame, it works 99% chances. The same issue can occur when switching to fullscreen on Mac OS X.
But what is a bit strange is that this issue shouldn't occur on Windows 32 bits. Have you checked the values that specify the dimension of your graphics-buffer ? For instance, getSize() should be replaced with calls to getWidth() and getHeight() for each component (c.f. javadoc).

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline MGodehardt

Junior Devvie




why does the chicken cross the road?


« Reply #2 - Posted 2007-12-06 16:40:20 »

Here is a little Test Programm you may run it under 1.6.0_03 as application or as applet

TestApplet.java Class

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
/**************************************************************************************************
 *
 *************************************************************************************************/


import java.applet.*;

/**************************************************************************************************
 *
 *************************************************************************************************/

public class TestApplet extends Applet
{
    private final static long serialVersionUID = 654321; // keep the compiler happy

    /**********************************************************************************************
     *
     *********************************************************************************************/

    public void init()
    {
    }

    /**********************************************************************************************
     *
     *********************************************************************************************/

    public void start()
    {
        TestFrame.main(null);
    }

    /**********************************************************************************************
     *
     *********************************************************************************************/

    public void stop()
    {
    }

    /**********************************************************************************************
     *
     *********************************************************************************************/

    public void destroy()
    {
    }
}

/*************************************************************************************************/


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
/**************************************************************************************************
 *
 *************************************************************************************************/


import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

import javax.swing.*;

/**************************************************************************************************
 *
 *************************************************************************************************/

public class TestFrame extends Frame
{
    private final static long serialVersionUID = 123456; // keep the compiler happy

    private final static int WIDTH = 900;
    private final static int HEIGHT = 700;

    /**********************************************************************************************
     *
     *********************************************************************************************/

    static public void main(String[] args)
    {
        try
        {
            TestFrame aFrame = new TestFrame();

            aFrame.enableEvents(AWTEvent.COMPONENT_EVENT_MASK);
            aFrame.setBounds(0, 0, TestFrame.WIDTH, TestFrame.HEIGHT);
            aFrame.setLayout(null);
            aFrame.setResizable(false);
            aFrame.setTitle("TestFrame");
            aFrame.setBackground(Color.red);
            aFrame.setVisible(true);
        }
        catch ( Exception ex )
        {
            ex.printStackTrace();
        }
    }

    /**********************************************************************************************
     * is called when parts of the peer are damaged and needs redraw
     *********************************************************************************************/

    protected void processComponentEvent(ComponentEvent e)
    {
        if ( e.getID() == ComponentEvent.COMPONENT_SHOWN )
        {
            setMinimumSize(new Dimension(812, 612));
            setLocation(10, 10);
            setMinimumSize(null);
            System.out.println("COMPONENT_SHOWN");
        }
    }

    /**********************************************************************************************
     * is called when parts of the peer are damaged and needs redraw
     *********************************************************************************************/

    public void paint(Graphics gg)
    {
        gg.setColor(Color.blue);
        gg.fillRect(0, 0, TestFrame.WIDTH - 20, TestFrame.HEIGHT - 20);

        gg.setColor(Color.black);
        gg.drawString("Hello World :-)", 20, 50);

        gg.drawString(getWidth() + "x" + getHeight(), 20, 100);
    }

    /**********************************************************************************************
     * triggered by repaint
     *********************************************************************************************/

    public void update(Graphics gg)
    {
        paint(gg);
    }
}

/*************************************************************************************************/


First run it with the processComponentEvent method commented out and you will see under a 800x600 desktop the window size is screen size minus screen insets, now uncomment the processComponentEvent and the window size is bigger.

Is this a bug ? or a feature ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline broumbroum

Junior Devvie





« Reply #3 - Posted 2007-12-06 17:16:27 »

I don't see any bugs. Your code is correct but what you want to do with the processComponentEvent must be validated by re-packing again the Frame.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
protected void processComponentEvent(ComponentEvent e)
    {
        if ( e.getID() == ComponentEvent.COMPONENT_SHOWN )
        {
            setMinimumSize(new Dimension(812, 612));
            setLocation(10, 10);
            setMinimumSize(null);
            pack();
            repaint();
            System.out.println("COMPONENT_SHOWN");
        }
    }
Smiley

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline MGodehardt

Junior Devvie




why does the chicken cross the road?


« Reply #4 - Posted 2007-12-07 16:20:00 »

I don't see any bugs. Your code is correct but what you want to do with the processComponentEvent must be validated by re-packing again the Frame.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
protected void processComponentEvent(ComponentEvent e)
    {
        if ( e.getID() == ComponentEvent.COMPONENT_SHOWN )
        {
            setMinimumSize(new Dimension(812, 612));
            setLocation(10, 10);
            setMinimumSize(null);
            pack();
            repaint();
            System.out.println("COMPONENT_SHOWN");
        }
    }
Smiley

pack is obsolete, i have no LayoutManager, i use setSize instead of pack, i tried it with pack and preferedSize ( which muste be set when using pack, otherwise window is very very small :-)

same result problem is not pack or setSize, Problem is java is limiting setSize, when i make the Frame resizable and the user ( me ) is making the frame bigger, its working ...

Workaround for Java 1.6 is using setMinimumSize which is forcing the window bigger :-)

I file this as bug and will post here the bug id when it is public available
Offline broumbroum

Junior Devvie





« Reply #5 - Posted 2007-12-07 20:00:29 »

yes, indeed setMininumSize() has been called twice. let the second call off and it should work. By the way, size cannot get under he preferredSize limit, but above. pack() is not obfuscating your layout, in fact it is null, but pack() has much more improvements to lay out the frame actually. resizing is much reflected if you want to display images. There's no bug about that. Do you have a link for tthe bug you submitted so that I can have something to refer to?

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (562 views)
2018-06-10 19:43:48

EgonOlsen (665 views)
2018-06-10 19:43:44

EgonOlsen (455 views)
2018-06-10 19:43:20

DesertCoockie (806 views)
2018-05-13 18:23:11

nelsongames (1025 views)
2018-04-24 18:15:36

nelsongames (1058 views)
2018-04-24 18:14:32

ivj94 (1637 views)
2018-03-24 14:47:39

ivj94 (562 views)
2018-03-24 14:46:31

ivj94 (1459 views)
2018-03-24 14:43:53

Solater (567 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!