views:

3512

answers:

3

I'm having a problem, creating a fixed-size overall panel for a touchscreen GUI application that has to take up the entire screen. In a nutshell, the touchscreen is 800 x 600 pixels, and therefore I want the main GUI panel to be that size.

When I start a new GUI project in NetBeans, I set the properties of the main panel for min/max/preferred size to 800 x 600, and the panel within the 'Design' view changes size. However, when I launch the app, it is resized to the original default size.

Adding this code after initComponents() does not help:

this.mainPanel.setSize(new Dimension(800,600));
this.mainPanel.setMaximumSize(new Dimension(800,600));
this.mainPanel.setMinimumSize(new Dimension(800,600));
this.mainPanel.repaint();

I've peeked into all of the resource files and cannot seem to find values that would override these (which seems somewhat impossible anyway, given that I'm setting them after initComponents() does its work). I'm using the FreeDesign layout, because I wanted complete control over where I put things.

I suspect the layout manager is resizing things based upon how many widgets I have on the screen, because different prototyped screens come in at differing sizes.

Help is appreciated!

A: 

I use this method to complete the task, not sure if its the best and you need to wait calling it until the frame is actually on the screen.

protected void growBig()
  {
    int screenWidth = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
    int screenHeight = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
    Rectangle rectangle = getFrame().getBounds();
    rectangle.setSize(screenWidth, screenHeight);
    getFrame().setBounds(0, 0, screenWidth, screenHeight);
    getFrame().setSize(screenWidth, screenHeight);
    getFrame().doLayout();
    getFrame().validate();
    updateUI();
  }
Peter
This did not work. The primary problem (I'm guessing) is that updateUI() does not resolve to the base class (FrameView), nor can I call it upon the top-level frame returned by getFrame(), upon which I exercised the re-size. The size is set according to the debugger, it just has no impact.
+1  A: 

Have you tried java full screen mode?

Chobicus
Thanks; this looks promising. I have it working on my local machine; now I just have to see if the touchscreen system supports it. Seems like it should...
A: 

I'm not sure how your touchscreen device works. But if you use Netbeans preview your panel is put in some outer container like JFrame/JWindow. And just maybe you set the frame to 800x600.

If so, then the problem might be that the frame eats a few pixels for its own border, leaving your panel size < 800x600. And in that case your panel will be unable to use your min/max settings and revert to default sizes.

Stroboskop
Well, it happens no matter the size of the panel (e.g. smaller or larger). It seems related to the outer JFrame size being set by some default resource, and wanting to resize based upon the widgets that I add. So, if it only has one button, it wants to be small, more larger, etc.
Note that this happens on my dev box, so isn't related to the touchscreen. Happens there, too, but it's not directly related to the touchscreen.