2

Is it possible to create a Window object of some sort in Java that has a frame and border, but no caption buttons (minimise, restore, close).

Naturally, I can't use the undecorated setting. Further, the window needs to:

  • Have a platform-rendered border
  • Have a titlebar
  • Have no caption buttons. If need be, I'll take care of disposing the window programmatically.
  • Use the default, or System Look and Feel

Here is an example:

captionless window

Redandwhite
  • 2,529
  • 4
  • 25
  • 43

3 Answers3

6

this is about

  1. decent How to Create Translucent and Shaped Windows

  2. undecorated JDialog with Compound Borders, then you can create similair or nicer Borders as came from Native OS

  3. create JPanel (orJLabel#opaque(true)) with GradientPaint

  4. or (better non_focusable == my view) JLabel with prepared Icon

  5. add to JPanel / JLabel the Component Mover / Component Resize (notice, don't never to mix these two codes together) by @camickr

  6. set Alpha Transparency for painting in JPanel / JLabel for great look and feel

  7. simplest of ways is put there JMenuBar

mKorbel
  • 109,525
  • 20
  • 134
  • 319
4

The short answer is no.

The longer answer is, probably, but you'll need to investigate a JNI/JNA implementation

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 2
    ... and the long and short of it is... it's probably not worth the effort in most cases – Redandwhite Sep 05 '12 at 10:34
  • not sure (as you mentioned you are Java1.3 dinosaurus, I'm from Java1.6.09) up to Java1.4 was possible to change DecorationsType without restrictions for Top-Level Containers +1 – mKorbel Sep 05 '12 at 11:12
2

Try this small example. It will remove (not only disable) minimse, maximise and close button from JFrame.

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

class Example {

    public void buildGUI() {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame();
        frame.setResizable(false);
        removeButtons(frame);
        JPanel panel = new JPanel(new GridBagLayout());
        JButton button = new JButton("Exit");
        panel.add(button,new GridBagConstraints());
        frame.getContentPane().add(panel);
        frame.setSize(400,300);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent a){
                System.exit(0);
            }
        });
    }

    public void removeButtons(Component comp) {
        if(comp instanceof AbstractButton) {
            comp.getParent().remove(comp);
        }
        if (comp instanceof Container) {
            Component[] comps = ((Container)comp).getComponents();
            for(int x=0, y=comps.length; x<y; x++) {
                removeButtons(comps[x]);
            }
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                new Example().buildGUI();
            }
        });
    }
}
lebryant
  • 351
  • 2
  • 18
  • 1
    Not a bad attempt. However, the window is not resizeable. Also, a requirement is that it uses the System look and feel. Changing to the system look and feel ruins it. Result: with your example on the left, and the same thing modified to use the default look and feel: http://i.imgur.com/pFSRy.png – Redandwhite Sep 05 '12 at 10:32