suspend the awt thread

2003-06-11 Thread Deblauwe, Wim
Title: suspend the awt thread





Hi,


I want to suspend the awt thread but still get painting done. Is this possible?


assume this piece of code:


actionPerformed(ActionEvent e)
{
 Runnable myRunnable = new MyRunnable();
 Thread workerThread = new Thread( myRunnable );
 workerThread.start();


 // Wait here for workerThread to finish
 // but still paint!


 Oject o = myRunnable.getObject();


 // do something with o
}


You are in the actionPerformed, so this gets executed on the awt thread. The workerThread starts with some lengthy operation and we want to wait in the actionPerformed for it to finish and then continue with our work. How do I do it?

kind regards,


Wim


-
Ing. Wim Deblauwe
Software Development Engineer
Medical Imaging Systems - BarcoView
- - - - - - - - DISCLAIMER - - - - - - - - 
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.




RE: suspend the awt thread

2003-06-11 Thread Deblauwe, Wim
Title: suspend the awt thread



Yes, 
a) is what I want to do. Now the progressbar is started in the MyRunnable() 
class. Are you saying that I should start it within the actionPerformed() 
method?

  -Original Message-From: Sachin Hejip 
  [mailto:[EMAIL PROTECTED]Sent: woensdag 11 juni 2003 
  8:45To: Deblauwe, Wim; [EMAIL PROTECTED]Subject: Re: 
  suspend the awt thread
  Sorry - sent it before completing my sentence - I meant to 
  say a) seems the best way . :-)
  
- Original Message - 
From: 
Sachin 
Hejip 
To: Deblauwe, Wim ; [EMAIL PROTECTED] 
Sent: Wednesday, June 11, 2003 12:14 
PM
Subject: Re: suspend the awt 
thread

Hey,

From what I understood what you wish to achieve is that 
the UI should continue to repaint but the user should not be able to 
interact with it while you complete your task?
You can - 
a) Show a modal dialog that says "Please Wait" or shows a 
progress bar preferably with a cancel button - this dialog disappears on the 
completion of your task. (I think this is the 
b) Disable all input event dispatching until your 
operation concludes by replacing the EventQueue with your own. 
c) A harder way to achieve this is to have the glass pane 
take focus, block mouse events and disable all menus.

Does this help?

Regards
Sachin

  - Original Message - 
  From: 
  Deblauwe, Wim 
  To: '[EMAIL PROTECTED]' 
  Sent: Wednesday, June 11, 2003 11:40 
  AM
  Subject: suspend the awt thread
  
  Hi, 
  I want to suspend the awt thread but still get painting 
  done. Is this possible? 
  assume this piece of code: 
  actionPerformed(ActionEvent e) {  Runnable myRunnable = new MyRunnable(); 
   Thread 
  workerThread = new Thread( myRunnable ); 
   workerThread.start(); 
   // Wait here 
  for workerThread to finish 
   // but still 
  paint! 
   Oject o = 
  myRunnable.getObject(); 
   // do something 
  with o } 
  You are in the actionPerformed, so this gets executed on 
  the awt thread. The workerThread starts with some lengthy operation and we 
  want to wait in the actionPerformed for it to finish and then continue 
  with our work. How do I do it?
  kind regards, 
  Wim 
  - Ing. Wim 
  Deblauwe Software Development Engineer 
  Medical Imaging Systems - BarcoView - - - - - - - - DISCLAIMER - - - - - - - - Unless indicated otherwise, the information contained in this 
  message is privileged and confidential, and is intended only for the use 
  of the addressee(s) named above and others who have been specifically 
  authorized to receive it. If you are not the intended recipient, you are 
  hereby notified that any dissemination, distribution or copying of this 
  message and/or attachments is strictly prohibited. The company accepts no 
  liability for any damage caused by any virus transmitted by this email. 
  Furthermore, the company does not warrant a proper and complete 
  transmission of this information, nor does it accept liability for any 
  delays. If you have received this message in error, please contact the 
  sender and delete the message. Thank 
  you.

- - - - - - - - DISCLAIMER - - - - - - - - 

Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.


RE: suspend the awt thread

2003-06-12 Thread Deblauwe, Wim
Title: suspend the awt thread



true, 
but what if it is not possible to do all operations in the 
Runnable?

  -Original Message-From: Sachin Hejip 
  [mailto:[EMAIL PROTECTED]Sent: woensdag 11 juni 2003 
  9:50To: Deblauwe, WimSubject: Re: suspend the awt 
  thread
  Do all your operations inside the runnable - finish off the 
  whole task inside the run method.
  
- Original Message - 
From: 
Deblauwe, Wim 
To: 'Sachin Hejip' 
Sent: Wednesday, June 11, 2003 1:17 
PM
Subject: RE: suspend the awt 
thread

But after the call:

new Thread(runnable).start();

I 
need to wait for the new Thread to finish, because I want to get some object 
from that runnable and it will only be available when the run() is 
completed.

I 
tried with:

while( thread.isAlive() )
{
 Thread.sleep(300);
}

but this sleeps the awt thread, so no painting happens 
anymore


  -Original Message-From: Sachin Hejip 
  [mailto:[EMAIL PROTECTED]Sent: woensdag 11 juni 2003 
  9:07To: Sachin Hejip; Deblauwe, Wim; 
  [EMAIL PROTECTED]Subject: Re: suspend the awt 
  thread
  Sorry, since the dialog is modal you need to show it in 
  the run of the runnable (again in the SwingUtilities and not in the 
  actionPerformed). 
  
  
  public void actionPerformed(ActionEvent ae) 
  {
   Runnable runnable = new Runnable() 
  {
public void run() 
  {
 
  startProgressDialog(); // remember to do this in the swing 
  thread 
  try {   
   // do some long operation and update progress dialog in 
  the Swing thread when appropriate
 
  } finally {
 
   closeProgressDialog(); // remember to do this in the 
  swing thread
}
   }
   new 
  Thread(runnable).start();
  }
  
- Original Message - 

From: 
Sachin 
Hejip 
To: Deblauwe, Wim ; [EMAIL PROTECTED] 
Sent: Wednesday, June 11, 
2003 12:33 PM
Subject: Re: suspend the 
awt thread

Yes, create the dialog and start the progress bar in 
the action peformed and then update it with calls to 
SwingUtilities.invokeLater in your MyRunnable class. Make sure you close 
the dialog in a finally block.



Hope this helps.
Regards
Sachin


  - Original Message - 
  
  From: 
  Deblauwe, Wim 
  To: 'Sachin 
  Hejip' ; [EMAIL PROTECTED] 
  Sent: Wednesday, June 
  11, 2003 12:18 PM
  Subject: RE: suspend the 
  awt thread
  
  Yes, a) is what I want to do. Now the 
  progressbar is started in the MyRunnable() class. Are you saying that 
  I should start it within the actionPerformed() 
  method?
  
-Original Message-From: Sachin Hejip 
[mailto:[EMAIL PROTECTED]Sent: woensdag 11 juni 2003 
8:45To: Deblauwe, Wim; [EMAIL PROTECTED]Subject: 
Re: suspend the awt thread
Sorry - sent it before completing my sentence - I 
meant to say a) seems the best way . :-)

  - Original Message 
  - 
  From: 
  Sachin Hejip 
  To: Deblauwe, Wim ; [EMAIL PROTECTED] 
  
  Sent: Wednesday, 
  June 11, 2003 12:14 PM
  Subject: Re: suspend 
  the awt thread
  
  Hey,
  
  From what I understood what you wish to achieve 
  is that the UI should continue to repaint but the user should not 
  be able to interact with it while you complete your 
  task?
  You can - 
  a) Show a modal dialog that says "Please Wait" 
  or shows a progress bar preferably with a cancel button - this 
  dialog disappears on the completion of your task. (I think this is 
  the 
  b) Disable all input event dispatching until 
  your operation concludes by replacing the EventQueue with your 
  own. 
  c) A harder way to achieve this is to have the 
  glass pane take focus, block mouse events and disable all 
  menus.
  
  Does this help?
  
  Regards
  Sachin
  
- Original Message 
- 
From: 
    Deblauwe, Wim 
To: '[EMAIL PROTECTED]' 

Sent: Wednesday, 
June 11, 2003 11:40 AM
Subject: suspend 
 

RE: weird focus behaviour with 2 JTextArea's

2003-10-30 Thread Deblauwe, Wim
Title: RE: weird focus behaviour with 2 JTextArea's





Thank you for your response and sorry about the import statements. I'm getting too used to using IntelliJ I'm afraid. There all I need to do is press ALT-ENTER, and import are automatically added.

kind regards,


Wim


-Original Message-
From: Joe Sam Shirah [mailto:[EMAIL PROTECTED]]
Sent: woensdag 29 oktober 2003 18:39
To: [EMAIL PROTECTED]
Subject: Re: weird focus behaviour with 2 JTextArea's




 Hi Wim,


 The same also happens with the second JTextArea if you press
Shift-Tab from the button. And for the same reasons. Change these
two lines in the MyTextArea constructor from true to false:



forwardFocusTraversalKeys.add(
 AWTKeyStroke.getAWTKeyStroke(
 KeyEvent.VK_TAB, 0, true ) );
...
backwardFocusTraversalKeys.add(
 AWTKeyStroke.getAWTKeyStroke(
 KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK, true ) );


 to



forwardFocusTraversalKeys.add(
 AWTKeyStroke.getAWTKeyStroke(
 KeyEvent.VK_TAB, 0, false ) );
...
backwardFocusTraversalKeys.add(
 AWTKeyStroke.getAWTKeyStroke(
 KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK, false ) );



 It's also helpful and likely to draw more response if you send
compilable code. That includes import statements. Best,



 Joe Sam


Joe Sam Shirah - http://www.conceptgo.com
conceptGO - Consulting/Development/Outsourcing
Java Filter Forum: http://www.ibm.com/developerworks/java/
Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
Going International? http://www.jguru.com/faq/I18N
Que Java400? http://www.jguru.com/faq/Java400




- Original Message -
From: Deblauwe, Wim [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, October 29, 2003 7:48 AM
Subject: weird focus behaviour with 2 JTextArea's



 Hi,

 I want enable TAB/SHIFT-TAB in a JTextArea to go to the next JTextArea and
 not print a tab character in the JTextArea. This can be easily done with
 setFocusTraversalKeys(). But I found something strange. Below is a
 testprogram with one JButton and 2 JTextArea's. When the program is
started,
 focus is on the JButton. Press TAB and the focus will go to the first
 JTextArea and immediately to the second JTextArea. If you place the focus
 with the mouse on the first JTextArea and press tab, it goes to the second
 as it should.

 Can someone explain this behaviour?

 Below is the code of my testprogram...

 public class FocusTest extends JFrame
 {
 public static void main( String[] args )
 {
 FocusTest test = new FocusTest();
 test.pack();
 test.setVisible(true);
 }

 public FocusTest() throws HeadlessException
 {
 super(Focus Test);
 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 setContentPane( createContent() );

 }

 private JPanel createContent()
 {
 JPanel panel = new JPanel();
 panel.setBorder( BorderFactory.createEmptyBorder(12,12,12,12));
 panel.setLayout( new BoxLayout(panel, BoxLayout.Y_AXIS));
 JButton button = new JButton(Test button);
 panel.add(button);

 JTextArea textArea1 = new MyTextArea();
 panel.add( textArea1 );

 panel.add( Box.createVerticalStrut(7));

 JTextArea textArea2 = new MyTextArea();
 panel.add( textArea2 );

 return panel;
 }

 private class MyTextArea extends JTextArea
 {
 public MyTextArea()
 {
 super(10, 50);
 Set forwardFocusTraversalKeys = new HashSet();


forwardFocusTraversalKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
 0, true));
 setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
 forwardFocusTraversalKeys);

 Set backwardFocusTraversalKeys = new HashSet();


backwardFocusTraversalKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
 InputEvent.SHIFT_DOWN_MASK, true));
 setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
 backwardFocusTraversalKeys);
 }
 }

 }


 Ing. Wim Deblauwe








___
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
- - - - - - - - DISCLAIMER - - - - - - - - 
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.




RE: Setting new JPane to a JFrame.

2004-01-19 Thread Deblauwe, Wim
Title: RE: Setting new JPane to a JFrame.





After this line:


m_frame.setContentPane(createPanel(fileChooser.getSelectedFile()));


put:


m_frame.validate();


or


m_frame.pack();


if the size of the frame should/can change.


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: maandag 19 januari 2004 9:07
To: [EMAIL PROTECTED]
Subject: Setting new JPane to a JFrame.



This is the most simple code that I found to show this error.


I have JFrame with a complex Content Pane (not this one). I'm trying to
recreate the Content pane for each File but after I set the new Content Pane
there is no Change, But if I try to resize the new Pane alredy apears. 


What do I need to set this simple example to work?


import java.awt.*;
import java.awt.event.*;
import java.io.*;


import javax.swing.*;


public class Main {
 static JFrame m_frame;
 public static void main(String[] args) {
 //Make sure we have nice window decorations.
 JFrame.setDefaultLookAndFeelDecorated(true);


 m_frame = new JFrame(Teste);
 m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


 m_frame.setContentPane(createPanel(null));


 m_frame.pack();
 m_frame.setVisible(true);
 }
 
 static JPanel createPanel(File file) {
 JPanel panel = new JPanel();
 JButton bRecreate = new JButton(Recreate);
 bRecreate.addActionListener(new ActionListener(){
 public void actionPerformed(ActionEvent arg0) {
 JFileChooser fileChooser = new JFileChooser();
 if (fileChooser.showOpenDialog(m_frame) != 
 JFileChooser.APPROVE_OPTION)
 return;

m_frame.setContentPane(createPanel(fileChooser.getSelectedFile()));


 }});
 JLabel label = new JLabel();
 if (file != null) {
 label.setText(file.getPath());
 }
 panel.add(label);
 panel.add(bRecreate);
 
 return panel;
 }
}
___
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
- - - - - - - - DISCLAIMER - - - - - - - - 
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.




RE: Path Files

2004-02-17 Thread Deblauwe, Wim
Title: RE: Path Files





Use the following construct:


ImageIcon image = new ImageIcon( getClass().getResource( images/file_close.gif ) );


This construct will find resources that are in the classpath.


Suppose this code is in a class in a package com.mycompagny.application, then you need to put the image in the directory com/mycompagny/application/images. This is because the getResource() method looks relative to the current package you are in.

Suppose you want to use the same image in a class in the package com.mycompagny.somepackage, but want to keep the image in the same location, then you can refer to it using:

ImageIcon image = new ImageIcon( getClass().getResource( /com/mycompagny/application/images/file_close.gif ) );


Notice the slash (/) at the start! By using that the package level you are currently in, is not taken into account. If you would leave out the slash before the com, then image would be searched in the directory com/mycompagny/somepackage/com/mycompagny/application/images

regards,


Wim




-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: dinsdag 17 februari 2004 12:39
To: [EMAIL PROTECTED]
Subject: Path Files



In my program I'm using ImageIcon for the buttons and I had this code


Action actClose = new AbstractAction(Close, new
ImageIcon(images/file_close.gif)){...}


This works if I'm in the correct directory, but if I'm not the images are
not found. 


What is the correct way to do the previus code?


Thanks
Marcos
___
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
- - - - - - - - DISCLAIMER - - - - - - - - 
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.