Frame decoration problems?

  • Follow


I'm working on an application and I would like to use the decorated look 
and feel on my frames and dialogs.  But I've run into a snag.  When you 
create a JFrame without the default L&F decoration, it is constrained in 
size by the screen dimensions (although is extends below the task bar in 
WinXP).  If I turn on the default L&F decoration the JFrame expands to 
the size of the components in the frame.  Anybody know how to get the 
decorated frame to act like an undecorated one?

Thanks,

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test {
     public static void main(String[] args) {
         Runnable r = new Runnable() {
             public void run() {
//****** uncomment the line below for undecorated frame ******* 

//                JFrame.setDefaultLookAndFeelDecorated(true);
                 class BigPanel extends JPanel {
                     public BigPanel() {
                         super();
                         setPreferredSize(new Dimension(400,2000));
                     }
                     public void paintComponent(Graphics g) {
                         g.setColor(Color.LIGHT_GRAY);
                         g.fillRect(0,0,getWidth(),getHeight());
                         g.setColor(Color.BLUE);
                         g.setFont(new Font("Arial",Font.BOLD,48));
                         FontMetrics fm = g.getFontMetrics();
                         int h = fm.getHeight();
                         int y = h;
                         while (y < getHeight()) {
                             g.drawString("Now is the time for all 
good",10,y);
                             y += h;
                         }
                     }
                 }

                 JFrame frame = new JFrame("test");
                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 BigPanel panel = new BigPanel();
                 JScrollPane sp = new JScrollPane(panel);
                 frame.add(sp);
                 frame.pack();
                 frame.setVisible(true);
             }
         };
         EventQueue.invokeLater(r);
     }
}

-- 

Knute Johnson
email s/nospam/knute/
0
Reply Knute 2/15/2006 2:18:09 AM

On Tue, 14 Feb 2006 18:18:09 -0800, Knute Johnson
<nospam@ljr-2.frazmtn.com> wrote, quoted or indirectly quoted someone
who said :

> Anybody know how to get the 
>decorated frame to act like an undecorated one?

Are you using pack or validate.  Try validate if you want something
other than the natural size.  The other approach would be to change
some components to ask for a smaller preferred size.
-- 
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
0
Reply Roedy 2/15/2006 3:45:42 AM


Roedy Green wrote:
> On Tue, 14 Feb 2006 18:18:09 -0800, Knute Johnson
> <nospam@ljr-2.frazmtn.com> wrote, quoted or indirectly quoted someone
> who said :
> 
>> Anybody know how to get the 
>> decorated frame to act like an undecorated one?
> 
> Are you using pack or validate.  Try validate if you want something
> other than the natural size.  The other approach would be to change
> some components to ask for a smaller preferred size.

Well what I really want to have happen is that the frame is as wide as 
it needs to be and only as tall as the open space (from the top of the 
task bar to the top of the screen) on the screen.  If the screen is 
maximized then it sets its height that like that but the width is the 
size of the screen too.

My actual program uses pack() as well as the small test program that I 
included.  I'm not sure why there is the difference between the two 
L&Fs.  I guess just for fun I should try it on a Linux machine too.

-- 

Knute Johnson
email s/nospam/knute/
0
Reply Knute 2/15/2006 4:23:28 AM

On Tue, 14 Feb 2006 20:23:28 -0800, Knute Johnson
<nospam@ljr-2.frazmtn.com> wrote, quoted or indirectly quoted someone
who said :

>My actual program uses pack() as well as the small test program that I 
>included.  I'm not sure why there is the difference between the two 
>L&Fs.  I guess just for fun I should try it on a Linux machine too.

You could do a pack. Look at the size. If you like it leave it. If not
redo it with a validate  choosing your own frame size based on the
screen dimensions.

See http://mindprod.com/jgloss/coordinates.html#SCREENSIZE

-- 
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
0
Reply Roedy 2/15/2006 5:28:31 AM

Roedy Green wrote:
> On Tue, 14 Feb 2006 20:23:28 -0800, Knute Johnson
> <nospam@ljr-2.frazmtn.com> wrote, quoted or indirectly quoted someone
> who said :
> 
>> My actual program uses pack() as well as the small test program that I 
>> included.  I'm not sure why there is the difference between the two 
>> L&Fs.  I guess just for fun I should try it on a Linux machine too.
> 
> You could do a pack. Look at the size. If you like it leave it. If not
> redo it with a validate  choosing your own frame size based on the
> screen dimensions.
> 
> See http://mindprod.com/jgloss/coordinates.html#SCREENSIZE
> 

I think that's what I'm going to do.

Thanks Roedy,

-- 

Knute Johnson
email s/nospam/knute/
0
Reply Knute 2/15/2006 5:30:15 AM

4 Replies
227 Views

(page loaded in 0.082 seconds)


Reply: