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);
}
}

Signature
Knute Johnson
email s/nospam/knute/
Roedy Green - 15 Feb 2006 03:45 GMT
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.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Knute Johnson - 15 Feb 2006 04:23 GMT
> On Tue, 14 Feb 2006 18:18:09 -0800, Knute Johnson
> <nospam@ljr-2.frazmtn.com> wrote, quoted or indirectly quoted someone
[quoted text clipped - 6 lines]
> 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.

Signature
Knute Johnson
email s/nospam/knute/
Roedy Green - 15 Feb 2006 05:28 GMT
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

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Knute Johnson - 15 Feb 2006 05:30 GMT
> On Tue, 14 Feb 2006 20:23:28 -0800, Knute Johnson
> <nospam@ljr-2.frazmtn.com> wrote, quoted or indirectly quoted someone
[quoted text clipped - 9 lines]
>
> See http://mindprod.com/jgloss/coordinates.html#SCREENSIZE
I think that's what I'm going to do.
Thanks Roedy,

Signature
Knute Johnson
email s/nospam/knute/