Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1.         // constantly overrides the value the user types in so every second character is reverted
  2.         protected void setComponent(final String t)
  3.         {
  4.             SwingUtilities.invokeLater(new Runnable(){
  5.                 @Override
  6.                 public void run()
  7.                 {
  8.                     try {
  9.                         document.remove(0,document.getLength());
  10.                         document.insertString(0,t,null);
  11.                     } catch (BadLocationException e) {
  12.                         LGM.showDefaultExceptionHandler(e);
  13.                     }
  14.                 }
  15.             });
  16.         }
  17.  
  18.     // errors like a mother and so does invokeAndWait which complains about not be allowed to be called from the Event Dispatch Thread
  19.     private void setComponentUnsafe(String t) {
  20.         try {
  21.             document.remove(0,document.getLength());
  22.             document.insertString(0,t,null);
  23.         } catch (BadLocationException e) {
  24.             LGM.showDefaultExceptionHandler(e);
  25.         }
  26.     }
  27.  
  28.     protected void setComponent(final String t)
  29.         {
  30.             if (!SwingUtilities.isEventDispatchThread()) {
  31.                 SwingUtilities.invokeLater(new Runnable(){
  32.                     @Override
  33.                     public void run()
  34.                     {
  35.                         setComponentUnsafe(t);
  36.                     }
  37.                 });
  38.             } else {
  39.                 setComponentUnsafe(t);
  40.             }
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement