Windows Server 2003 中的 Java swing 错误

发布于 2024-12-26 11:46:45 字数 158 浏览 1 评论 0原文

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

任何帮助将不胜感激。

I am facing a weird issue where it seems that the PropertyChange event for a combobox is not getting fired in Windows Server 2003. I have made the application in Java Swing. When I run the application on other OS it seems to be working fine.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§对你不离不弃 2025-01-02 11:46:45

只是我的好奇心,这段代码适用于 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);
    }
}

just my curiosity this code works on WinXP/Win2003 and Win7/Win2008 various JRE6_XX_XXX, can you please put there your workaround for 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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文