English 中文(简体)
周转活动过滤器
原标题:swing event filter
  • 时间:2012-01-12 11:44:00
  •  标签:
  • java
  • swing

能否为某些集装箱内的所有控制安装过滤器?

例如,我有一个小组,有2个县和1个小组,有2个文本箱,我希望能够接收所有涉及这些控制的活动(布顿和文字箱)。

UPD There are four controls:

JPanel mainPanel = new JPanel(new BorderLayout());
JButton b1 = new JButton();
JButton b2 = new JButton();
mainPanel.add(b1, BorderLayout.WEST);
mainPanel.add(b2, BorderLayout.EAST);

JPanel childPanel = new JPanel(new FlowLayout());
JTextField txt1 = new JTextField();
JTextField txt2 = new JTextField();
childPanel.add(txt1);
childPanel.add(txt2);
mainPanel.add(childPanel, BorderLayout.SOUTH);

EventDispatchingMachine.attachEventListener(mainPanel, listener);

www.un.org/spanish/ecosoc 收到所有涉及b1、b2、txt1、txt2的事件。 最好是通过听众处理具体控制问题的每一项活动(例如b1.addActionListener(asd)) 我想在<代码>listener上接收。

最佳回答

In jdk7 you can use JLayer to decorate any component with listeners:

    LayerUI<JComponent> ui = new LayerUI<JComponent>() {

        @Override
        protected void processMouseEvent(MouseEvent e, JLayer<? extends JComponent> l) {
             System.out.println(e.getSource().getClass() + " at " + e.getPoint());
        } 
    };
    JLayer<JComponent> layer = new JLayer<JComponent>(mainPanel, ui);
    layer.setLayerEventMask(AWTEvent.MOUSE_EVENT_MASK );   

(关于jdk6,有支持同一项目的JXLayer)

<><>Edit>/strong>

在对这一问题进行二读时,答案可以是“不可能”:事件! 你们可以(通过一个电算师或人工操作的AWTEventListener)登记,接收全球发送的所有活动。 我们不能把“当地”发送的活动视为“当地”发送活动,因为行动手段被简单地用作受人直接呼吁的已知反馈方法的参数。

问题回答

you have look at EventListenerList, then you can take all Listener into Array,

If you want to intercept events before they are dispatched to a component then check out Global Event Dispatching.

如果你只想听取所有活动的发言,那么将检查Global Activities Listeners

在这两种情况下,你们都需要核对活动的来源,以确定活动是否属于小组的组成部分。

然而,我认为,这不会赶上“行动环境”,因为这不是一次系统活动,而是在 Java为某个具体组成部分的变迁/转用活动。

如果我们知道过滤的原因,我们或许可以提供一种替代方法。 例如,或许你试图创建Disabled Panel?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签