Prev: gcj compiled executable performance
Next: Writing jnlp program for both sandbox and all-permissions
From: Robbo on 26 Mar 2010 18:22 Hello, I have strange problem. There is split pane in my application. I added my own event listeners to both touch buttons -- after that there are oryginal listeners which do all work and my listeners which enable or distable left button. The purpose of my code was to be possible to show/hide bottom panel and never hide top panel. But (I am not sure that it is only situation) when I play fast with one touch buttons, sometimes my listeners don't get event! Oryginal listeners get event because they always show/hide panel, but my listeners don't -- so sometimes one touch buttons do nothing after click. Please, play for a moment with these buttons and you will see. Please, help me to solve this problem. Regards, Robbo import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.plaf.basic.*; public class Swing5 { public static void main(String[] args) { new Swing5(); } public Swing5() { JFrame f = new JFrame("Swing5"); f.setSize(300, 100); Container c = f.getContentPane(); c.setLayout(new BorderLayout()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p1 = new JPanel(); p1.setPreferredSize(new Dimension(300, 100)); JPanel p2 = new JPanel(); p2.setMinimumSize(new Dimension(0, 50)); p2.setMaximumSize(new Dimension(0, 50)); p2.setPreferredSize(new Dimension(300, 50)); JSplitPane sp1 = new JSplitPane(); sp1.setDividerSize(15); sp1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); sp1.setResizeWeight(1.0); sp1.setOneTouchExpandable(true); sp1.setTopComponent(p1); sp1.setBottomComponent(p2); sp1.setUI(new BasicSplitPaneUI() { public BasicSplitPaneDivider createDefaultDivider() { return new BasicSplitPaneDivider(this) { boolean isSmallPanelOpened = true; public void setBasicSplitPaneUI(BasicSplitPaneUI newUI) { super.setBasicSplitPaneUI(newUI); splitPane.removePropertyChangeListener(this); if (mouseHandler != null) { splitPane.removeMouseListener(mouseHandler); splitPane.removeMouseMotionListener(mouseHandler); removeMouseListener(mouseHandler); removeMouseMotionListener(mouseHandler); } setCursor(java.awt.Cursor.getPredefinedCursor( java.awt.Cursor.DEFAULT_CURSOR)); if (leftButton.isEnabled() == false) return; leftButton.setEnabled(false); leftButton.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.out.println("left"); if (!leftButton.isEnabled()) return; leftButton.setEnabled(false); } }); rightButton.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.out.println("right"); leftButton.setEnabled(true); } }); } }; } }); c.add(sp1); f.pack(); f.setVisible(true); } }
From: Robbo on 26 Mar 2010 20:10 Hm... this seems to work better: import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.plaf.basic.*; public class Swing5 { public static void main(String[] args) { new Swing5(); } public Swing5() { JFrame f = new JFrame("Swing5"); f.setSize(300, 100); Container c = f.getContentPane(); c.setLayout(new BorderLayout()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p1 = new JPanel(); p1.setPreferredSize(new Dimension(300, 100)); JPanel p2 = new JPanel(); p2.setMinimumSize(new Dimension(0, 50)); p2.setMaximumSize(new Dimension(0, 50)); p2.setPreferredSize(new Dimension(300, 50)); JSplitPane sp1 = new JSplitPane(); sp1.setDividerSize(15); sp1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); sp1.setResizeWeight(1.0); sp1.setOneTouchExpandable(true); sp1.setTopComponent(p1); sp1.setBottomComponent(p2); sp1.setUI(new BasicSplitPaneUI() { public BasicSplitPaneDivider createDefaultDivider() { return new BasicSplitPaneDivider(this) { public void setBasicSplitPaneUI(BasicSplitPaneUI newUI) { super.setBasicSplitPaneUI(newUI); leftButton.setEnabled(false); leftButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (!leftButton.isEnabled()) return; leftButton.setEnabled(false); } }); rightButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { leftButton.setEnabled(true); } }); splitPane.removePropertyChangeListener(this); if (mouseHandler != null) { splitPane.removeMouseListener(mouseHandler); splitPane.removeMouseMotionListener(mouseHandler); removeMouseListener(mouseHandler); removeMouseMotionListener(mouseHandler); } setCursor(java.awt.Cursor.getPredefinedCursor( java.awt.Cursor.DEFAULT_CURSOR)); } }; } }); c.add(sp1); f.pack(); f.setVisible(true); } }
From: Roedy Green on 29 Mar 2010 18:39 On Fri, 26 Mar 2010 23:22:06 +0100, "Robbo" <nie.mam(a)yle.com> wrote, quoted or indirectly quoted someone who said : >But (I am not sure that it is only situation) when >I play fast with one touch buttons, sometimes >my listeners don't get event! Usually clogging the EDT thread is the problem. For an event to be processed, the EDT thread must be unbusy enough to process the event packets in the queue. Make sure you don't tie up the Event thread for long periods of time. Consider putting anything time consuming on its own thread. Consider splitting up long chunks on the EDT thread into separate chunks so some even processing can be interleaved. Make sure you never sleep on the EDT. Redesign your repaint logic so that you don't repaint until all the changes are complete, and you repaint only the clip regions that could have changed. -- Roedy Green Canadian Mind Products http://mindprod.com If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure they stay in sync, the versions of the fact will eventually get out of sync.
|
Pages: 1 Prev: gcj compiled executable performance Next: Writing jnlp program for both sandbox and all-permissions |