Jay Gridley
Jay Gridley

Reputation: 723

Preserve border after removing title bar from JFrame

I want to remove title bar from JFrame, so I call setUndecorated(true) on that JFrame, but I would like to preserve border (nifty gradient) on that JFrame, which is present when decoration is on? Can I do that? Something like getting border instance for LookAndFeel default or make gradient border myself?

Upvotes: 0

Views: 2356

Answers (2)

Mikle Garin
Mikle Garin

Reputation: 10153

The default system LookAndFeel window borders are drawn by system, not Java, so there is no way to remove title bar from the window alone. The only thing you can do is undecorate your window and draw border by yourself (and yes, to fully copy system border you will have to put a lot of effort into it).

Maybe something like that could be available in SWT, but to use it you will have to abandon standart Swing.

Upvotes: 2

Qwerky
Qwerky

Reputation: 18455

You can accomplish this visually by creating a JPanel and giving it a border, then setting the panel as your frame's content.

public class Undecorated {

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

    JPanel borderedPanel = new JPanel();

    //Use any border you want, eg a nice blue one
    borderedPanel.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.BLUE));

    frame.setContentPane(borderedPanel);
    frame.setUndecorated(true);
    frame.setSize(new Dimension(200, 200));
    frame.setVisible(true);
  }

}

Upvotes: 1

Related Questions