自定义关闭和最小化按钮

RAJ*_* KV 0 java swing look-and-feel

我有一个装饰JFrame.我需要关闭按钮并最小化按钮.我该怎么办?

这是我的代码片段:

public Startup()
{
    setTitle("STARTUP");
    setSize(800,500);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setUndecorated(true);
    setLocationRelativeTo(null);
    setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)

Hun*_*Dev 5

你的方法非常独特,看起来很不错.有很多方法可以解决您的问题.现在,根据您的要求,您需要CLOSE一个MINIMIZE按钮.让我们做以下几点Action.

private final Action exitAction = new AbstractAction("Exit")
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            System.exit(0);
        }
    };
private final Action minimizeAction = new AbstractAction("Minimize")
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            setState(JFrame.ICONIFIED);
        }
    };
Run Code Online (Sandbox Code Playgroud)

现在,让我们将上述操作应用于JButtons:

JButton closeButton = new JButton(exitAction);
JButton miniButton = new JButton(minimizeAction);
Run Code Online (Sandbox Code Playgroud)

你有它.现在,您需要做的就是将按钮添加到您的按钮中JFrame.