gpt4 book ai didi

Windows Server 2003 中的 Java swing 错误

转载 作者:行者123 更新时间:2023-11-30 04:54:59 25 4
gpt4 key购买 nike

我遇到了一个奇怪的问题,似乎组合框的 PropertyChange 事件在 Windows Server 2003 中没有被触发。我已经在 J​​ava Swing 中创建了该应用程序。当我在其他操作系统上运行该应用程序时,它似乎工作正常。

如有任何帮助,我们将不胜感激。

最佳答案

只是我的好奇心,这段代码适用于WinXP/Win2003Win7/Win2008各种JRE6_XX_XXX,您能否将您的解决方法放在那里JComboBox

import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;

public class TestPropListener {

private static final Color TRUE_COLOR = new Color(180, 200, 255);
protected static final Color FALSE_COLOR = new Color(255, 100, 100);

private static void createAndShowUI() {
final MyBean panel = new MyBean();
panel.setTitle(true);
//panel.setPreferredSize(new Dimension(400, 400));
panel.setBackground(TRUE_COLOR);
panel.addMouseListener(new MouseAdapter() {

@Override
public void mousePressed(MouseEvent e) {
panel.setTitle(!panel.getTitle());
}
});
panel.addPropertyChangeListener(new PropertyChangeListener() {

@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(MyBean.TITLE_PROP_NAME)) {
panel.setBackground(panel.getTitle() ? TRUE_COLOR : FALSE_COLOR);
}
}
});
JFrame frame = new JFrame("Test Property Listener");
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,300);
//frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {

@Override
public void run() {
createAndShowUI();
}
});
}

private TestPropListener() {
}
}

class MyBean extends JPanel {

public final static String TITLE_PROP_NAME = "title";
private static final long serialVersionUID = 1L;
private boolean title;
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);

public boolean getTitle() {
return this.title;
}

public void setTitle(boolean title) {
boolean old = this.title;
this.title = title;
this.pcs.firePropertyChange(TITLE_PROP_NAME, old, title);
}

@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
this.pcs.addPropertyChangeListener(listener);
}

@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
this.pcs.removePropertyChangeListener(listener);
}
}

关于Windows Server 2003 中的 Java swing 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8821417/

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