gpt4 book ai didi

java - Eclipse WindowBuilder 错误?

转载 作者:行者123 更新时间:2023-11-29 03:51:32 29 4
gpt4 key购买 nike

我正在制作一个 Java 应用程序,用于修补模组并将纹理包添加到 Minecraft 中。我希望它使用通过 DJ 项目 JWebBrowser 访问的在线模组商店。我正在使用 Eclipse WindowBuilder/手动编码来构建 UI。我的问题是 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)

奇怪的是,如果我正常运行它,它就可以正常工作。这是相关的源代码:

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

当我在这里时,mntmQuit 按钮没有做任何事情。我调试了它,当我点击它时它甚至没有运行 mouseClicked 事件。我正在使用 java 1.6、WindowBuilder 1.2.0.r37、Eclipse Indigo,如有任何帮助,我们将不胜感激!

最佳答案

我可以回答你一半的问题 - 也许通过澄清我会弄清楚剩下的问题。

您需要将 ActionListener 附加到 JMenuItem,而不是 MouseListener。请参阅 Oracle 教程 How to Use Menus一些很好的例子。

关于java - Eclipse WindowBuilder 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8570472/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com