简体   繁体   English

Eclipse WindowBuilder Bug?

[英]Eclipse WindowBuilder Bug?

I am making a java application for patching mods and adding texture packs into Minecraft. 我正在制作一个java应用程序,用于修补mod并将纹理包添加到Minecraft中。 I want it to use a online mod store accessed through the DJ Project JWebBrowser. 我希望它使用通过DJ Project JWebBrowser访问的在线mod商店。 I am using Eclipse WindowBuilder/hand coding to construct the UI. 我正在使用Eclipse WindowBuilder /手动编码来构建UI。 My problem is that WindowBuilder crashes with the following error 我的问题是WindowBuilder崩溃时出现以下错误

    Stack trace:
java.lang.IllegalArgumentException: Width (125) and height (0) cannot be <= 0
    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
    at java.awt.image.BufferedImage.<init>(Unknown Source)
    at chrriis.dj.nativeswing.swtimpl.core.SWTNativeComponent.print(SWTNativeComponent.java:845)
    at sun.awt.windows.WComponentPeer.print(Unknown Source)
    at java.awt.GraphicsCallback$PeerPrintCallback.run(Unknown Source)
    at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
    at java.awt.Component.printAll(Unknown Source)
    at org.eclipse.wb.internal.swing.utils.SwingImageUtils$2.run(SwingImageUtils.java:104)
    at org.eclipse.wb.internal.swing.utils.SwingImageUtils.runInDispatchThread(SwingImageUtils.java:554)
    at org.eclipse.wb.internal.swing.utils.SwingImageUtils.createComponentShotAWT(SwingImageUtils.java:102)
    at org.eclipse.wb.internal.swing.utils.SwingImageUtils.makeShotsHierarchy(SwingImageUtils.java:235)
    at org.eclipse.wb.internal.swing.utils.SwingImageUtils.makeShotsHierarchy(SwingImageUtils.java:261)
    at org.eclipse.wb.internal.swing.utils.SwingImageUtils.makeShotsHierarchy(SwingImageUtils.java:261)
    at org.eclipse.wb.internal.swing.utils.SwingImageUtils.makeShotsHierarchy(SwingImageUtils.java:261)
    at org.eclipse.wb.internal.swing.utils.SwingImageUtils.makeShotsHierarchy(SwingImageUtils.java:261)

The weird thing is that it works if I run it normally it works just fine. 奇怪的是,如果我正常运行它可以正常工作。 Here is the relevant source code: 这是相关的源代码:

setTitle("OpenMPatch");
        getContentPane().setLayout(new BorderLayout(0, 0));

        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        getContentPane().add(tabbedPane);

        JPanel tabModStore = new JPanel();
        tabbedPane.addTab("Mod Store", null, tabModStore, "Mod Store");

        JWebBrowser modStore = new JWebBrowser();
        modStore.setStatusBarVisible(false);
        tabModStore.add(modStore);

        JPanel tabSettings = new JPanel();
        tabbedPane.addTab("Settings", null, tabSettings, "Settings");

        comboBoxTheme = new JComboBox();
        comboBoxTheme.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                setLAF(comboBoxTheme.getSelectedItem().toString());
            }
        });
        comboBoxTheme.setModel(new DefaultComboBoxModel(new String[] {
                "system", "java", "motif", "nimbus", "windows",
                "windowsclassic" }));
        try {
            comboBoxTheme.setSelectedItem(Config.ReadConfig().get("LAF"));
        } catch (Exception e) {
            e.printStackTrace();
            OpenMPatch.error(e);
        }

        JLabel lblTheme = new JLabel("Theme:");
        lblTheme.setLabelFor(comboBoxTheme);
        lblTheme.setFont(new Font("Tahoma", Font.PLAIN, 12));
        lblTheme.setHorizontalAlignment(SwingConstants.RIGHT);

        JButton btnSaveSettings = new JButton("Save Settings");
        btnSaveSettings.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                saveSettings();
            }
        });

        JButton btnRestoreDefualts = new JButton("Restore Defualts");
        btnRestoreDefualts.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                try {
                    Config.restoreDefualts();
                    updateSettings();
                } catch (Exception e) {
                    e.printStackTrace();
                    error(e);
                }
            }
        });
// Generated by WindowBuilder
        GroupLayout gl_tabSettings = new GroupLayout(tabSettings);
        gl_tabSettings
                .setHorizontalGroup(gl_tabSettings
                        .createParallelGroup(Alignment.LEADING)
                        .addGroup(
                                gl_tabSettings
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addGroup(
                                                gl_tabSettings
                                                        .createParallelGroup(
                                                                Alignment.LEADING)
                                                        .addGroup(
                                                                gl_tabSettings
                                                                        .createSequentialGroup()
                                                                        .addComponent(
                                                                                lblTheme)
                                                                        .addPreferredGap(
                                                                                ComponentPlacement.RELATED)
                                                                        .addComponent(
                                                                                comboBoxTheme,
                                                                                GroupLayout.PREFERRED_SIZE,
                                                                                GroupLayout.DEFAULT_SIZE,
                                                                                GroupLayout.PREFERRED_SIZE))
                                                        .addGroup(
                                                                gl_tabSettings
                                                                        .createSequentialGroup()
                                                                        .addComponent(
                                                                                btnSaveSettings)
                                                                        .addPreferredGap(
                                                                                ComponentPlacement.RELATED)
                                                                        .addComponent(
                                                                                btnRestoreDefualts)))
                                        .addContainerGap(365, Short.MAX_VALUE)));
        gl_tabSettings
                .setVerticalGroup(gl_tabSettings
                        .createParallelGroup(Alignment.LEADING)
                        .addGroup(
                                gl_tabSettings
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addGroup(
                                                gl_tabSettings
                                                        .createParallelGroup(
                                                                Alignment.BASELINE)
                                                        .addComponent(lblTheme)
                                                        .addComponent(
                                                                comboBoxTheme,
                                                                GroupLayout.PREFERRED_SIZE,
                                                                GroupLayout.DEFAULT_SIZE,
                                                                GroupLayout.PREFERRED_SIZE))
                                        .addGap(18)
                                        .addGroup(
                                                gl_tabSettings
                                                        .createParallelGroup(
                                                                Alignment.BASELINE)
                                                        .addComponent(
                                                                btnSaveSettings)
                                                        .addComponent(
                                                                btnRestoreDefualts))
                                        .addContainerGap(274, Short.MAX_VALUE)));
        tabSettings.setLayout(gl_tabSettings);

        JPanel statusBar = new JPanel();
        statusBar.setToolTipText("Status");
        getContentPane().add(statusBar, BorderLayout.SOUTH);

        setIconImage(Toolkit.getDefaultToolkit().getImage(
                OpenMPatch.class.getResource("/alex/mik/openmpatch/icon.png")));

        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);

        JMenu mnFile = new JMenu("File");
        menuBar.add(mnFile);

        JMenuItem mntmOpenFile = new JMenuItem("Open File...");
        mntmOpenFile.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent paramMouseEvent) {

            }
        });
        mntmOpenFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
                InputEvent.CTRL_MASK));
        mnFile.add(mntmOpenFile);

        JMenuItem mntmOpenFolder = new JMenuItem("Open Folder...");
        mntmOpenFolder.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
                InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
        mnFile.add(mntmOpenFolder);

        JSeparator fileSeparator1 = new JSeparator();
        mnFile.add(fileSeparator1);

        JMenuItem mntmQuit = new JMenuItem("Quit");
        mntmQuit.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                close();
            }
        });
        mntmQuit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
                InputEvent.CTRL_MASK));
        mnFile.add(mntmQuit);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        pack();

And while I am here, the mntmQuit button does not do anything. 当我在这里时,mntmQuit按钮没有做任何事情。 I debugged it and it did not even run the mouseClicked event when I clicked on it. 我调试了它,当我点击它时它甚至没有运行mouseClicked事件。 I am using java 1.6, WindowBuilder 1.2.0.r37, Eclipse Indigo, and any help would be appreciated! 我正在使用java 1.6,WindowBuilder 1.2.0.r37,Eclipse Indigo,任何帮助将不胜感激!

I can answer half your question - maybe with clarification I'll figure out the rest. 我可以回答你的一半问题 - 也许澄清我会弄清楚剩下的。

You need to attach an ActionListener to a JMenuItem , not a MouseListener . 您需要将ActionListener附加到JMenuItem ,而不是MouseListener See Oracle's tutorial How to Use Menus for some very good examples. 有关一些非常好的示例,请参阅Oracle的教程如何使用菜单

Actually, based on the exception, it looks like the chrriis.dj.nativeswing.swtimpl.core.SWTNativeComponent class caused the problem and WindowBuilder trapped the error for you. 实际上,基于异常,它看起来像chrriis.dj.nativeswing.swtimpl.core.SWTNativeComponent类导致了问题,WindowBuilder为您捕获了错误。 I assume it showed you this on the Design page (as it is designed to do) and did not actually "crash". 我假设它在“设计”页面上显示了这一点(因为它的设计目的)并且实际上并没有“崩溃”。

@Paul - WindowBuilder already generates very clear and very maintainable code, so there would be no reason to "ditch" it. @Paul - WindowBuilder已经生成了非常清晰且可维护的代码,因此没有理由“抛弃”它。 It also extremely compatible with hand made mods so you can easily work back and forth in source or design mode, and WB will keep both in sync at all times. 它还与手工制作的mod非常兼容,因此您可以轻松地在源或设计模式下来回工作,WB将始终保持同步。

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

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