标题可能不合适,但这里是完整的解释
我需要的是我的框架应该有3个按钮(最小化,最大化,关闭),但框架的边框应该是自定义的(某些颜色/渐变)。
编辑:我还没有开始编码,因为我不知道从哪里开始
答案 0 :(得分:2)
答案 1 :(得分:0)
一些外观和感觉支持JFrame装饰,例如标准的装饰,Metal:
您可以使用LookAndFeel.getSupportsWindowDecorations()
来检查LaF是否支持装饰。
通过修改LaF,您可以更改框架装饰的绘制方式。
或者,您可以创建一个没有装饰的框架。在框架实例上调用setUndecorated(true)
:
因此,您可以在内容窗格中轻松绘制所需内容。然而,除非您自己实现这些功能,否则这样的窗口不能轻易移动,调整大小,最小化或最大化。
你可以找到有趣的文章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
您可以使用这些文章中的代码作为实现自己的框架装饰的基础。