[英]Netbeans GUI preview is different from Runtime view
I'm developing a simple Java application using NetBeans and its GUI editor. 我正在使用NetBeans及其GUI编辑器开发一个简单的Java应用程序。 I'm stuck on creating a simple dialog: runtime it looks different from what I designed and from what is previewed in the editor.
我一直在创建一个简单的对话框:运行时它与我设计的内容和编辑器中预览的内容不同。 Basically, clicking on a button make my dialog appears.
基本上,单击按钮会显示我的对话框。
private void jButton1MouseReleased(java.awt.event.MouseEvent evt) {
PanelDialogNuovoCliente pan = new PanelDialogNuovoCliente();
JDialog jd=new JDialog();
jd.setTitle("Nuovo Cliente");
jd.setMinimumSize(new Dimension(500, 400));
jd.setLocationRelativeTo(null);
jd.add(pan);
jd.setModal(true);
jd.setVisible(true);
}
The problem is that when the dialog appears it has a different look, the dialog window seems smaller and not all the components fit in it. 问题是当对话框出现时它具有不同的外观,对话框窗口看起来更小,而不是所有组件都适合它。
PanelDialogNuovoCliente
is just a JPanel
with some labels and JTextField
. PanelDialogNuovoCliente
只是一个带有一些标签和JTextField
的JPanel
。
Maximum, Minimum and Preferred sizes are all set to (500,400) from the JPanel
properties in the editor. 最大,最小和首选大小都从编辑器中的
JPanel
属性设置为(500,400)。
JDialog
minimum size is set to (500,400) from the code that I snipped. JDialog
最小大小设置为(500,400)我剪切的代码。
Unfortunately I can't post a screenshot because I need at least 10 reputation but when I run the application Dialog's window is smaller compared to the one that I can see from the preview button in NetBean's GUI editor. 不幸的是我无法发布截图,因为我需要至少10个声誉,但是当我运行应用程序时,对话框的窗口比我从NetBean的GUI编辑器中的预览按钮看到的窗口要小。
EDIT: Here's the screenshot. 编辑:这是截图。 Runtime JDialog is on the left, while preview of it in netbeans is on the right.
运行时JDialog位于左侧,而netbeans中的预览位于右侧。 I tried to call JDialog#pack() just before setVisible(true) without success.
我试图在setVisible(true)之前调用JDialog#pack()但没有成功。 I set nimbus look and feel for my app.
我为我的应用设置了nimbus的外观和感觉。 Anyways if i try to preview the design from ide with nimbus l&f it looks perfect so i don't think that this one is the real problem
无论如何,如果我尝试使用nimbus l&f预览ide的设计,它看起来很完美,所以我不认为这个是真正的问题
Perhaps what you're experiencing is similar to this post: 也许你所经历的与这篇文章类似:
NetBeans (Java Swing): Set window size NetBeans(Java Swing):设置窗口大小
I remember experiencing something similar and shared my experiences in a post there. 我记得经历过类似的事情并在那里分享我的经历。
Edit: (28/05/2015) 编辑:(28/05/2015)
Just to clarify/elaborate, here are steps I've got to replicate (and resolve) the issue I encountered, which might be what you've faced. 只是为了澄清/阐述,这里是我必须复制(并解决)我遇到的问题的步骤,这可能是你所面临的问题。
Problem Replication Steps 问题复制步骤
Workaround 解决方法
I tried the workaround suggested in Tomas Pavek's post here: 我尝试了Tomas Pavek在帖子中提出的解决方法:
http://forums.netbeans.org/ptopic28011.html http://forums.netbeans.org/ptopic28011.html
Basically, these steps: 基本上,这些步骤:
...and hey presto! ......嘿嘿! It appears at the correct size that the IDE had specified.
它显示为IDE指定的正确大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.