Netbeans GUI预览与运行视图不同 [英] Netbeans GUI preview is different from Runtime view

查看:198
本文介绍了Netbeans GUI预览与运行视图不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NetBeans及其GUI编辑器开发一个简单的Java应用程序。
我坚持创建一个简单的对话框:运行时它看起来不同于我设计的和编辑器中预览的内容。
基本上,点击一个按钮会使我的对话框出现。

  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);
}

问题是当对话框出现时有不同的外观,对话框窗口似乎更小,并不是所有组件都适合。



PanelDialogNuovoCliente 只是一个 JPanel 带有一些标签和 JTextField



最大,最小和首选大小都是在编辑器中的 JPanel 属性中设置为(500,400)。



JDialog 最小尺寸从我剪切的代码设置为(500,400)。



不幸的是,我不能发布屏幕截图,因为我需要至少10个声誉但是当我运行应用程序时,对话框的窗口与NetBean GUI编辑器中的预览按钮相比,窗口更小。



编辑:屏幕截图。运行时JDialog位于左侧,而netbeans中的预览位于右侧。我试图在setVisible(true)之前调用JDialog#pack()而不成功。我设置nimbus外观和感觉我的应用程序无论如何,如果我尝试从ide与nimbus l& f预览设计,它看起来完美,所以我不认为这是真正的问题

解决方案

或许你遇到的是类似于帖子:



NetBeans(Java Swing):设置窗口大小



我记得遇到类似的东西,并分享了我在一篇文章中的经验。



编辑:(28/05/2015)



只是为了澄清/阐述,这里是我必须复制的步骤(并解决)我遇到的问题,哪些可能是您所面对的问题。



问题复制步骤


  1. 使用文件>>新建项目...创建一个新项目

  2. 选择 Java >> Java桌面应用程序

  3. 点击下一步按钮

  4. 项目名称: TestApp ,然后完成按钮 - 然后,您可以在Matisse编辑器TestView.java(应用程序的主窗口)和TestAboutBox .java。

  5. 在Matisse编辑器中,我将窗口重新设置为大尺寸

  6. 然后按 Ctrl + F5 来运行

  7. 它运行,窗口与ide中的大小相同。

  8. 关闭应用程序后,它将数据写入我的linux系统
    上的〜/ .TestApp / mainFrame.session.xml 文件(我认为这相当于 %APPDATA%\CompanyName\TestApp\mainFrame.session.xml 在Windows系统上)

  9. 查看这个 mainFrame.session。 xml 文件,我看到有一个 mainFrame 节点包含 x y width 高度

  10. 回到mattisse编辑器,我调整窗口的大小。 li>
  11. 然后按 Ctrl + F5 再次运行

  12. 然后应用程序的窗口显示为较大的大小(即,它没有遵守IDE中指定的较小的大小)

解决方法



我尝试在Tomas Pavek的帖子中提出的解决方法:



http://forums.netbeans.org/ptopic28011.html



基本上,这些步骤:


  1. 删除此 mainFrame.session.xml 文件(或包含该文件的文件夹)

  2. 然后执行 CTRL + F5 再次运行应用程序

...嘿急!它出现在IDE指定的正确大小。


I'm developing a simple Java application using NetBeans and its GUI editor. 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.

Maximum, Minimum and Preferred sizes are all set to (500,400) from the JPanel properties in the editor.

JDialog minimum size is set to (500,400) from the code that I snipped.

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.

EDIT: Here's the screenshot. Runtime JDialog is on the left, while preview of it in netbeans is on the right. I tried to call JDialog#pack() just before setVisible(true) without success. I set nimbus look and feel for my app. 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

解决方案

Perhaps what you're experiencing is similar to this post:

NetBeans (Java Swing): Set window size

I remember experiencing something similar and shared my experiences in a post there.

Edit: (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

  1. Create a new project with "File >> New Project..."
  2. Choose "Java >> Java Desktop Application"
  3. Click 'Next' button
  4. Project Name: "TestApp", then "Finish" button - You then get two tabs opening up in the Matisse editor, "TestView.java" (the app's main window) and "TestAboutBox.java".
  5. In the Matisse editor, I re-size the window to be a large size.
  6. I then press Ctrl+F5 to run it
  7. It runs and the window is the same size as in the ide.
  8. Upon closing the app, it writes data to a "~/.TestApp/mainFrame.session.xml" file on my linux system (I think this equates to "%APPDATA%\CompanyName\TestApp\mainFrame.session.xml" on a windows system)
  9. Taking a look inside this "mainFrame.session.xml" file, I see there's a "mainFrame" node that contains the x, y, width and height of the window.
  10. Back in the mattisse editor, I resize the window to be smaller.
  11. I then press Ctrl+F5 to run it again
  12. The app's window then appears at the larger size (ie, it didn't abide by the smaller size specified in the IDE)

Workaround

I tried the workaround suggested in Tomas Pavek's post here:

http://forums.netbeans.org/ptopic28011.html

Basically, these steps:

  1. Delete this "mainFrame.session.xml" file (or the folder that contains it)
  2. then do CTRL+F5 to run the app again

...and hey presto! It appears at the correct size that the IDE had specified.

这篇关于Netbeans GUI预览与运行视图不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆