How can I implement new JFrame functionality

I am trying to remove a drag panel at the top of a JFrame. I would like to minimize to a minimum and close the parameters that appear on this bar. What I was thinking about is removing the panel (and icons). Then add icons in the form of inline images that implement the JFrame actionlistener. You will also need to work with JInternalFrames for this. Any help would be greatly appreciated.

+3
source share
4 answers

You need to step back and understand how Swing works.

When you create a JFrame, Swing uses the OS widget for the frame. The title bar that you see is part of the OS component and you do not have direct control over it with Swing. You can hide the title (and border) of the frame using setUndecorated (false), as suggested earlier. In this case, you will lose all the functionality associated with the title (drag and drop and access to all buttons) and border (resize). Therefore, if you need any of these functions, you need to recreate it all yourself.

Alternatively, you can use:

JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame();

Swing Border . , , JFrame , , . , MouseMotionListeners , . , , , . , .

, JInternalFrame - , Swing, , , JFrame.

+4

,

setUndecorated(true);

/. ( ). JFrame.ICONIFIED .

JButton btnMaximize = new JButton("+");
btnMaximize.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        if(MainFrame.this.getExtendedState() == JFrame.MAXIMIZED_BOTH) {
            MainFrame.this.setExtendedState(JFrame.NORMAL);
        }
        else {
            MainFrame.this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        }
    }
});
+1

Take a look at this article - I think this is pretty much what you need for the JFrame part.

http://www.stupidjavatricks.com/?p=4

It is based on JDialog, but it should be almost the same as JFrame. Maximize / Minimize should be about the same as the close button.

+1
source

For JInternalFrames ...

javax.swing.plaf.InternalFrameUI ifu= this.getUI();
((javax.swing.plaf.basic.BasicInternalFrameUI)ifu).setNorthPane(null);
-1
source

Source: https://habr.com/ru/post/1726278/


All Articles