简体   繁体   English

为什么我的swing GUI在设计上看起来与运行时不同?

[英]Why does my swing GUI look different in design than at run-time?

When I design my GUI using swing, the Swing Control Buttons are grey and the text easily fits on them. 当我使用swing设计我的GUI时,Swing控制按钮是灰色的,文本很容易适合它们。 However, when I run the program the buttons become partly blue and the text no longer fits on them. 但是,当我运行程序时,按钮变为部分蓝色,文本不再适合它们。 Why does my program look different in the Swing Design than at run-time? 为什么我的程序在Swing设计中看起来与运行时不同?

Why does my program look different in the Swing Design than at run-time? 为什么我的程序在Swing设计中看起来与运行时不同?

Probably has something to do with your Look and Feel . 可能与你的外观有关

However, when I run the program the buttons become partly blue and the text no longer fits on them. 但是,当我运行程序时,按钮变为部分蓝色,文本不再适合它们。

Probably because you are not using layout managers . 可能是因为您没有使用布局管理器 Layout managers will make sure components are displayed properlly, even when switching between LAF's. 布局管理器将确保组件正确显示,即使在LAF之间切换也是如此。

I can't guess what tool you are using to create your GUI but you are doing something wrong with the tool. 我无法猜测您使用什么工具来创建GUI,但是您正在使用该工具做错了什么。 If you need more help then post your SSCCE that demonstrates the problem. 如果您需要更多帮助,请发布证明问题的SSCCE

I suppose you're using some GUI builder. 我想你正在使用一些GUI构建器。 Netbeans gui builder displays preview with native LaF, while program runs with default Metal LaF, which has different margins for components and font size. Netbeans gui builder使用原生LaF显示预览,而程序使用默认的Metal LaF运行,它具有不同的组件边距和字体大小。 Either change LaF in your program to the one that works best for your layout, or make your components larger. 将程序中的LaF更改为最适合您的布局的LaF,或者将组件放大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM