java - 如何将 JWindow 添加到 NetBeans 项目并使用 GUI 编辑器进行编辑?

标签 java swing netbeans-7

只有一个选项可以将 JFrame 和 JPanel 添加到项目中。我尝试编辑 JFrame 类来扩展 JWindow,但它使 NetBeans 自动生成的代码出现错误,并且无法编辑此代码。

最佳答案

您可以创建自己的模板...

将这两个文件放入 ...\NetBeans\7.2.1\config\Templates\GUIForms 文件夹中。

在 Windows 7 上,该位置为 C:\Users\{您的用户名}\AppData\Roaming\NetBeans\7.2.1\config\Templates\GUIForms

JWindow.java

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && package != "">
package ${package};

</#if>
/**
 *
 * @author ${user}
 */
public class ${name} extends javax.swing.JWindow {

    /** Creates new form ${name} */
    public ${name}() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        pack();
    }
    // </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ${name}().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}

JWindow.form

<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
  <SyntheticProperties>
    <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
  </SyntheticProperties>

</Form>

关于java - 如何将 JWindow 添加到 NetBeans 项目并使用 GUI 编辑器进行编辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15059032/

相关文章:

java - Apache Commons Exec 更改 PATH 并执行 virtualenv 的 pip

java - 在 Docker 上运行 Java Swing GUI 应用程序

jakarta-ee - Netbeans 7.3.1 添加服务器 Glassfish 4.1

java - java中的curl命令

java - 如何在 SQLite 中测试早于当前日期的日期

java - Android如何在应用程序处于手机后台时运行任务

java - 当卡片布局中的面板出现时如何执行某些操作

java - 为什么 java swing gui 绘制不好?

Netbeans 中的 JavaScript

Java桌面应用程序: How to fix height and width