用3个按钮绘制自己的框架

时间:2013-12-25 09:31:43

标签: java swing frame

标题可能不合适,但这里是完整的解释

我需要的是我的框架应该有3个按钮(最小化,最大化,关闭),但框架的边框应该是自定义的(某些颜色/渐变)。

看到这个: Preview http://getintopc.com/wp-content/uploads/2013/06/corel-videostudio-pro-x6-free-download-features.jpg

编辑:我还没有开始编码,因为我不知道从哪里开始

2 个答案:

答案 0 :(得分:2)

将所需的内部框架图标(见here)添加到未修饰框架中的容器中,图示为here

答案 1 :(得分:0)

一些外观和感觉支持JFrame装饰,例如标准的装饰,Metal:

Frame with LaF decorated border

您可以使用LookAndFeel.getSupportsWindowDecorations()来检查LaF是否支持装饰。

通过修改LaF,您可以更改框架装饰的绘制方式。

或者,您可以创建一个没有装饰的框架。在框架实例上调用setUndecorated(true)

Frame without decorations

因此,您可以在内容窗格中轻松绘制所需内容。然而,除非您自己实现这些功能,否则这样的窗口不能轻易移动,调整大小,最小化或最大化。

你可以找到有趣的文章Windows Java tip: How to control window decorations


我使用了以下AFrame class

public class AFrame {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame.setDefaultLookAndFeelDecorated(true);
                JFrame frame = new JFrame("A Frame");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                frame.setSize(200, 100);
                frame.setLocationByPlatform(true);

                frame.setVisible(true);
            }
        });
    }

}

创建没有边框的框架:

  • 删除行JFrame.setDefaultLookAndFeelDecorated(true);
  • 添加行frame.setUndecorated(true);

更新:我发现了一系列关于如何为Nimbus外观添加框架装饰的文章:

第3步的框架看起来是这样的:
Nimbus Look and Feel frame decorations: 3rd step rendering http://weblogs.java.net/sites/default/files/ThirdStep.png

您可以使用这些文章中的代码作为实现自己的框架装饰的基础。