Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Where is my JFrame? (was Strange behavior when trying to debug my application within eclipse)
Where is my JFrame? (was Strange behavior when trying to debug my application within eclipse) [message #322457] Mon, 19 November 2007 07:38 Go to next message
Eclipse UserFriend
Originally posted by: yaronrein.hotmail.com

Hi,

I was able to isolate the problem.to the following program, it runs well
from the command line but fail to show the frame when running within Eclipse
Why does System.in.read(buffer); prevent the frame creation within Eclipse?

Thanks in advance
/Yaron

import java.io.IOException;


import javax.swing.JFrame;



public class WhereIsMyJFrame

{

public static void main(String[] args)

{

new WhereIsMyJFrame();

}


private WhereIsMyJFrame()

{

Thread thread = new Thread()

{

public void run()

{

System.out.println("run");

WhereIsMyJFrame.loop();

}

};


System.out.println("starting the thread");

thread.start();


System.out.println("creating the main window");

JFrame frame = new JFrame("WhereIsMyJFrame");

System.out.println("main window created");

frame.setVisible(true);

}




private static void loop()

{

try

{

byte buffer[] = { 0 };

do

System.in.read(buffer);

while ((char) buffer[0] != 'x');

}

catch (IOException ioexception)

{

ioexception.printStackTrace();

}

}

}
Re: Where is my JFrame? (was Strange behavior when trying to debug my application within eclipse) [message #322459 is a reply to message #322457] Mon, 19 November 2007 08:22 Go to previous messageGo to next message
Eclipse UserFriend
Maybe because the streams in Eclipse are redirected to the ConsoleView?

Tom

Yaron Reinharts schrieb:
> Hi,
>
> I was able to isolate the problem.to the following program, it runs well
> from the command line but fail to show the frame when running within Eclipse
> Why does System.in.read(buffer); prevent the frame creation within Eclipse?
>
> Thanks in advance
> /Yaron
>
> import java.io.IOException;
>
>
> import javax.swing.JFrame;
>
>
>
> public class WhereIsMyJFrame
>
> {
>
> public static void main(String[] args)
>
> {
>
> new WhereIsMyJFrame();
>
> }
>
>
> private WhereIsMyJFrame()
>
> {
>
> Thread thread = new Thread()
>
> {
>
> public void run()
>
> {
>
> System.out.println("run");
>
> WhereIsMyJFrame.loop();
>
> }
>
> };
>
>
> System.out.println("starting the thread");
>
> thread.start();
>
>
> System.out.println("creating the main window");
>
> JFrame frame = new JFrame("WhereIsMyJFrame");
>
> System.out.println("main window created");
>
> frame.setVisible(true);
>
> }
>
>
>
>
> private static void loop()
>
> {
>
> try
>
> {
>
> byte buffer[] = { 0 };
>
> do
>
> System.in.read(buffer);
>
> while ((char) buffer[0] != 'x');
>
> }
>
> catch (IOException ioexception)
>
> {
>
> ioexception.printStackTrace();
>
> }
>
> }
>
> }
>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Where is my JFrame? (was Strange behavior when trying to debug my application within eclipse) [message #322465 is a reply to message #322459] Mon, 19 November 2007 11:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yaronrein.hotmail.com

Hi,

Thanks but I don't see how it can prevents the creation of a JFrame

/Yaron
"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:fhs2mh$5r5$1@build.eclipse.org...
> Maybe because the streams in Eclipse are redirected to the ConsoleView?
>
> Tom
>
> Yaron Reinharts schrieb:
>> Hi,
>>
>> I was able to isolate the problem.to the following program, it runs well
>> from the command line but fail to show the frame when running within
>> Eclipse
>> Why does System.in.read(buffer); prevent the frame creation within
>> Eclipse?
>>
>> Thanks in advance
>> /Yaron
>>
>> import java.io.IOException;
>>
>>
>> import javax.swing.JFrame;
>>
>>
>>
>> public class WhereIsMyJFrame
>>
>> {
>>
>> public static void main(String[] args)
>>
>> {
>>
>> new WhereIsMyJFrame();
>>
>> }
>>
>>
>> private WhereIsMyJFrame()
>>
>> {
>>
>> Thread thread = new Thread()
>>
>> {
>>
>> public void run()
>>
>> {
>>
>> System.out.println("run");
>>
>> WhereIsMyJFrame.loop();
>>
>> }
>>
>> };
>>
>>
>> System.out.println("starting the thread");
>>
>> thread.start();
>>
>>
>> System.out.println("creating the main window");
>>
>> JFrame frame = new JFrame("WhereIsMyJFrame");
>>
>> System.out.println("main window created");
>>
>> frame.setVisible(true);
>>
>> }
>>
>>
>>
>>
>> private static void loop()
>>
>> {
>>
>> try
>>
>> {
>>
>> byte buffer[] = { 0 };
>>
>> do
>>
>> System.in.read(buffer);
>>
>> while ((char) buffer[0] != 'x');
>>
>> }
>>
>> catch (IOException ioexception)
>>
>> {
>>
>> ioexception.printStackTrace();
>>
>> }
>>
>> }
>>
>> }
>>
>>
>>
>
>
> --
> B e s t S o l u t i o n . at
> ------------------------------------------------------------ --------
> Tom Schindl JFace-Committer
> ------------------------------------------------------------ --------
Re: Where is my JFrame? (was Strange behavior when trying to debug my application within eclipse) [message #322467 is a reply to message #322465] Mon, 19 November 2007 11:42 Go to previous messageGo to next message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------060706090601070409050807
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Yaron,

I don't really know how eclipse handles calls to System.out and
System.in, but I guess both of them are redirected to the console view.
This is no more than a wild guess, but since you're calling thread.start
(which in turns will take the consoleView over with a call to
System.in.read()) before creating and displaying your window, I think
the call to System.out.println("main window created") will wait for the
consoleView to be released before continuing execution.

Cheers,
Laurent Goubet
Obeo

Yaron Reinharts a
Re: Where is my JFrame? (was Strange behavior when trying to debug my application within eclipse) [message #322499 is a reply to message #322467] Tue, 20 November 2007 01:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yaronrein.hotmail.com

This makes sense, and I can understand why the "main window created" is not
diaplayed, however, it doesn't explain where is the JFrame and why I can see
the JFrame only when running outside Eclipse
Any idea?

Thanks
/Yaron


"laurent Goubet" <laurent.goubet@obeo.fr> wrote in message
news:fhse8b$cb6$1@build.eclipse.org...
> Yaron,
>
> I don't really know how eclipse handles calls to System.out and
> System.in, but I guess both of them are redirected to the console view.
> This is no more than a wild guess, but since you're calling thread.start
> (which in turns will take the consoleView over with a call to
> System.in.read()) before creating and displaying your window, I think
> the call to System.out.println("main window created") will wait for the
> consoleView to be released before continuing execution.
>
> Cheers,
> Laurent Goubet
> Obeo
>
> Yaron Reinharts a
Re: Where is my JFrame? (was Strange behavior when trying to debug my application within eclipse) [message #322513 is a reply to message #322499] Tue, 20 November 2007 03:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: akarypid.yahoo.gr

If you debug your application, you'll see that if you interrupt the main
thread you'll see it's within:

WDesktopProperties.init() line: not available [native method]

whereas the other thread is

FileInputStream.readBytes(byte[], int, int) line: not available
[native method]

My guess is that the Swing library somehow accesses the console in
WDesktopProperties.init() causing a deadlock. I'd use an object to wait
for the frame to become visible before proceeding with console access:

public void run() {
synchronized (sync) {
try {
sync.wait();
} catch (InterruptedException e) {
return;
}
}
// ...

and

private WhereIsMyJFrame() {
// ...
JFrame frame = new JFrame("WhereIsMyJFrame");
synchronized (sync) {
sync.notify();
}
System.out.println("main window created");
frame.setVisible(true);

Also, I'd guess that you could reproduce this thing outside of Eclipse
if you ran your program from the command line and redirected your
standard input and output.
Re: Where is my JFrame? (was Strange behavior when trying to debug my application within eclipse) [message #322520 is a reply to message #322513] Tue, 20 November 2007 05:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yaronrein.hotmail.com

Thank you Alexandros

I don't see this thread in the debug window
I see other threads, there are all seems to be running (including one which
is called AWT-Shutdown)
I'm using Eclipse Version 3.3.1

Anyway, I found a workaround for my problem (skipping the console reading)
However, I'm still curious to understand what happened and to know if I
should do something about it (bug report)

Thanks
/Yaron

"Alexandros Karypidis" <akarypid@yahoo.gr> wrote in message
news:47429F85.3040509@yahoo.gr...
> If you debug your application, you'll see that if you interrupt the main
> thread you'll see it's within:
>
> WDesktopProperties.init() line: not available [native method]
> whereas the other thread is
>
> FileInputStream.readBytes(byte[], int, int) line: not available [native
> method]
> My guess is that the Swing library somehow accesses the console in
> WDesktopProperties.init() causing a deadlock. I'd use an object to wait
> for the frame to become visible before proceeding with console access:
>
> public void run() {
> synchronized (sync) {
> try {
> sync.wait();
> } catch (InterruptedException e) {
> return;
> }
> }
> // ...
>
> and
>
> private WhereIsMyJFrame() {
> // ...
> JFrame frame = new JFrame("WhereIsMyJFrame");
> synchronized (sync) {
> sync.notify();
> }
> System.out.println("main window created");
> frame.setVisible(true);
>
> Also, I'd guess that you could reproduce this thing outside of Eclipse if
> you ran your program from the command line and redirected your standard
> input and output.
Re: Where is my JFrame? (was Strange behavior when trying to debug my application within eclipse) [message #322527 is a reply to message #322520] Tue, 20 November 2007 07:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: akarypid.yahoo.gr

Yaron Reinharts wrote:
> Thank you Alexandros
>
> I don't see this thread in the debug window
> I see other threads, there are all seems to be running (including one which

Yes, this is correct. You will see all threads there as "running", even
though the thread may just be waiting in vain for something to occur.

There is an "interrupt" button which will change the thread's state to
susspended and show you where the thread instruction pointer is at,
along with a stack trace of how it got there.

In order to see meaningful names, call "setName()" on your threads to
give them human-readable descriptions. Then you can know which thread is
what.

> is called AWT-Shutdown)
> I'm using Eclipse Version 3.3.1
>
> Anyway, I found a workaround for my problem (skipping the console reading)
> However, I'm still curious to understand what happened and to know if I
> should do something about it (bug report)

In any case if you _require_ console input, I'm pretty sure you can have
it and still work around this (as described in my previous post) by
having the thread's run() method wait for the JFrame constructor to
return and then access the console.

> Thanks
> /Yaron
>
> "Alexandros Karypidis" <akarypid@yahoo.gr> wrote in message
> news:47429F85.3040509@yahoo.gr...
>> If you debug your application, you'll see that if you interrupt the main
>> thread you'll see it's within:
>>
>> WDesktopProperties.init() line: not available [native method]
>> whereas the other thread is
>>
>> FileInputStream.readBytes(byte[], int, int) line: not available [native
>> method]
>> My guess is that the Swing library somehow accesses the console in
>> WDesktopProperties.init() causing a deadlock. I'd use an object to wait
>> for the frame to become visible before proceeding with console access:
>>
>> public void run() {
>> synchronized (sync) {
>> try {
>> sync.wait();
>> } catch (InterruptedException e) {
>> return;
>> }
>> }
>> // ...
>>
>> and
>>
>> private WhereIsMyJFrame() {
>> // ...
>> JFrame frame = new JFrame("WhereIsMyJFrame");
>> synchronized (sync) {
>> sync.notify();
>> }
>> System.out.println("main window created");
>> frame.setVisible(true);
>>
>> Also, I'd guess that you could reproduce this thing outside of Eclipse if
>> you ran your program from the command line and redirected your standard
>> input and output.
>
>
Re: Where is my JFrame? (was Strange behavior when trying to debug my application within eclipse) [message #322725 is a reply to message #322527] Tue, 27 November 2007 02:44 Go to previous message
Eclipse UserFriend
Originally posted by: yaronrein.hotmail.com

Thakns again, it was very helpful
/Yaron
"Alexandros Karypidis" <akarypid@yahoo.gr> wrote in message
news:4742CF72.30801@yahoo.gr...
> Yaron Reinharts wrote:
>> Thank you Alexandros
>>
>> I don't see this thread in the debug window
>> I see other threads, there are all seems to be running (including one
>> which
>
> Yes, this is correct. You will see all threads there as "running", even
> though the thread may just be waiting in vain for something to occur.
>
> There is an "interrupt" button which will change the thread's state to
> susspended and show you where the thread instruction pointer is at, along
> with a stack trace of how it got there.
>
> In order to see meaningful names, call "setName()" on your threads to give
> them human-readable descriptions. Then you can know which thread is what.
>
>> is called AWT-Shutdown)
>> I'm using Eclipse Version 3.3.1
>>
>> Anyway, I found a workaround for my problem (skipping the console
>> reading)
>> However, I'm still curious to understand what happened and to know if I
>> should do something about it (bug report)
>
> In any case if you _require_ console input, I'm pretty sure you can have
> it and still work around this (as described in my previous post) by having
> the thread's run() method wait for the JFrame constructor to return and
> then access the console.
>
>> Thanks
>> /Yaron
>>
>> "Alexandros Karypidis" <akarypid@yahoo.gr> wrote in message
>> news:47429F85.3040509@yahoo.gr...
>>> If you debug your application, you'll see that if you interrupt the main
>>> thread you'll see it's within:
>>>
>>> WDesktopProperties.init() line: not available [native method]
>>> whereas the other thread is
>>>
>>> FileInputStream.readBytes(byte[], int, int) line: not available [native
>>> method]
>>> My guess is that the Swing library somehow accesses the console in
>>> WDesktopProperties.init() causing a deadlock. I'd use an object to wait
>>> for the frame to become visible before proceeding with console access:
>>>
>>> public void run() {
>>> synchronized (sync) {
>>> try {
>>> sync.wait();
>>> } catch (InterruptedException e) {
>>> return;
>>> }
>>> }
>>> // ...
>>>
>>> and
>>>
>>> private WhereIsMyJFrame() {
>>> // ...
>>> JFrame frame = new JFrame("WhereIsMyJFrame");
>>> synchronized (sync) {
>>> sync.notify();
>>> }
>>> System.out.println("main window created");
>>> frame.setVisible(true);
>>>
>>> Also, I'd guess that you could reproduce this thing outside of Eclipse
>>> if you ran your program from the command line and redirected your
>>> standard input and output.
>>
Previous Topic:Problem creating POJO using Castor data binding framework in Eclipse plugin
Next Topic:How to access all projects at runtime
Goto Forum:
  


Current Time: Sat Jul 19 01:22:33 EDT 2025

Powered by FUDForum. Page generated in 0.27729 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top