what i do wrong???  
Author Message
hitman





PostPosted: 2003-6-26 20:55:00 Top

java-programmer, what i do wrong??? Hello All!

I think I have a mistake in my logical sequence of thoughts...

When I want to take influence on my JComponents (JTextField,
JCheckBox, etc.),
do I have to place a listener within the constructor???

My problem was the following. I wanted to get the values from my
different JTextFields an write them to any *.txt file. That did only
work, when I inserted a KeyListener who registered any changes in the
text fields. But my real problem is now, to get the values back from
the *.txt file an set them with setText(String) in the text fields.
This don't work.
I have seen in the NG, that there will be oft spoken about
revalidate() or repaint(), but that don't work anyway.
It does not matter, what I want to do - set a component enabled, or
disabled or what ever, I have to have an adequate listener within the
constructor so that the changes will be visible, isn't it that way???
For example:

public void any_method()
{
myTextfield.setEnabled(false);
}
// IT DON'T WORK
// ...but I don't know why. When I put it within the constructor, it
works...

I don't know what to to. I know it from MFC, there I could get
influence on my components in any method.

I don't know what I do wrong in Java.
(My program is an application with JFrame and SWING componets. I use
JTabbedPane and for each tab a Jpanel)

There must be a simple solution for my problem (I hope so).
Please led me out from this dead-end street.

Thanks in advance

Dariusz
 
Jacob





PostPosted: 2003-6-26 21:33:00 Top

java-programmer >> what i do wrong??? Darius wrote:
> But my real problem is now, to get the values back from
> the *.txt file an set them with setText(String) in the text fields.
> This don't work.

Try to be more specific about what exactly
is your problem. I am not sure what you mean
by taking "influence" on your component.

Assuming that the setText() is actually your
problem; Did you check the value of the text?
(Has it been read correctly from file?)
Do you call setText() on the right component?
Is setText() called later from elsewhere
and thereby override your setting?

Listeners and repainting has nothing to do
with this (but might possibly mess things up
for you if done terribly wrong).

 
hitman





PostPosted: 2003-6-27 4:50:00 Top

java-programmer >> what i do wrong??? Jacob <email***@***.com> wrote in message news:<email***@***.com>...
> Darius wrote:
> > But my real problem is now, to get the values back from
> > the *.txt file an set them with setText(String) in the text fields.
> > This don't work.
>
> Try to be more specific about what exactly
> is your problem. I am not sure what you mean
> by taking "influence" on your component.
>
> Assuming that the setText() is actually your
> problem; Did you check the value of the text?
> (Has it been read correctly from file?)
> Do you call setText() on the right component?
> Is setText() called later from elsewhere
> and thereby override your setting?
>
> Listeners and repainting has nothing to do
> with this (but might possibly mess things up
> for you if done terribly wrong).

Hi Jacob!

Thanks for prompt answer. You're right, the informations I wrote are
barely.
I try once more.

With 'influence' I mean that I can use different methods for any
JComponents.
So on JTextField i can use setText(), setEnabled() or what ever. The
problem is, if I do this outer the constructor it doesn't work. I wish
I could set a method (which would be invoked by any other) how the
following for example:

setTextvalue()
{
myTextField.setEditable(false);
}

So if the method would be invoked I would expect she would do what I
expect her to. But she does nothing.

By MFC, there was a method 'update(boolean)'.
In Java I know only the one way - to invoke the method from
constructor.
For example:

public MyClass extends JFrame
{
public JTextField myTextField;

public MyClass()
{
...

myTextField = new JTextField(20);
setTextvalue();
}
...
}

I heard about validate() and revalidate(), but they didn't work too. I
don't know what have to be revalidate. The JTextField? The JPanel? The
JTabbedPane (I use in my app)? I don't know. I tried out all, but no
one worked.
There is something idon't know. It can be so complicated...

I hope I could better depict the situation.
 
 
dfdfd





PostPosted: 2003-6-27 20:20:00 Top

java-programmer >> what i do wrong??? All of your Swing gui method calls have to be done on the Swing event
thread. Are
you trying to call setText() from a different thread?

"Darius" <email***@***.com> wrote in message
news:email***@***.com...
> Jacob <email***@***.com> wrote in message
news:<email***@***.com>...
> > Darius wrote:
> > > But my real problem is now, to get the values back from
> > > the *.txt file an set them with setText(String) in the text fields.
> > > This don't work.
> >
> > Try to be more specific about what exactly
> > is your problem. I am not sure what you mean
> > by taking "influence" on your component.
> >
> > Assuming that the setText() is actually your
> > problem; Did you check the value of the text?
> > (Has it been read correctly from file?)
> > Do you call setText() on the right component?
> > Is setText() called later from elsewhere
> > and thereby override your setting?
> >
> > Listeners and repainting has nothing to do
> > with this (but might possibly mess things up
> > for you if done terribly wrong).
>
> Hi Jacob!
>
> Thanks for prompt answer. You're right, the informations I wrote are
> barely.
> I try once more.
>
> With 'influence' I mean that I can use different methods for any
> JComponents.
> So on JTextField i can use setText(), setEnabled() or what ever. The
> problem is, if I do this outer the constructor it doesn't work. I wish
> I could set a method (which would be invoked by any other) how the
> following for example:
>
> setTextvalue()
> {
> myTextField.setEditable(false);
> }
>
> So if the method would be invoked I would expect she would do what I
> expect her to. But she does nothing.
>
> By MFC, there was a method 'update(boolean)'.
> In Java I know only the one way - to invoke the method from
> constructor.
> For example:
>
> public MyClass extends JFrame
> {
> public JTextField myTextField;
>
> public MyClass()
> {
> ...
>
> myTextField = new JTextField(20);
> setTextvalue();
> }
> ...
> }
>
> I heard about validate() and revalidate(), but they didn't work too. I
> don't know what have to be revalidate. The JTextField? The JPanel? The
> JTabbedPane (I use in my app)? I don't know. I tried out all, but no
> one worked.
> There is something idon't know. It can be so complicated...
>
> I hope I could better depict the situation.


 
 
Daniel Dyer





PostPosted: 2003-6-27 20:29:00 Top

java-programmer >> what i do wrong??? On Fri, 27 Jun 2003 12:19:59 GMT, dfdfd <email***@***.com> wrote:

> All of your Swing gui method calls have to be done on the Swing event
> thread. Are
> you trying to call setText() from a different thread?

setText(String text) is one of the few Swing methods that is thread-safe.

--
Daniel Dyer
Empathy Software (http://www.empathysoftware.com)


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
 
 
usenet





PostPosted: 2003-6-28 6:33:00 Top

java-programmer >> what i do wrong??? Hello!

Daniel Dyer <email***@***.com> wrote:

> On Fri, 27 Jun 2003 12:19:59 GMT, dfdfd <email***@***.com> wrote:
>
>> All of your Swing gui method calls have to be done on the Swing event
>> thread. Are
>> you trying to call setText() from a different thread?
>
> setText(String text) is one of the few Swing methods that is thread-safe.

It is one of the Swing methods that is incorrectly documented to be
thread-safe.



Christian
--
http://www.chka.de/swing/text/threads.html
 
 
slim.shady





PostPosted: 2003-7-4 3:34:00 Top

java-programmer >> what i do wrong??? Hi!

THANKS for you answers!

How can I know, which thread will be used at the moment?

Greetings

Dariusz


email***@***.com (Christian Kaufhold) wrote in message news:<email***@***.com>...
> Hello!
>
> Daniel Dyer <email***@***.com> wrote:
>
> > On Fri, 27 Jun 2003 12:19:59 GMT, dfdfd <email***@***.com> wrote:
> >
> >> All of your Swing gui method calls have to be done on the Swing event
> >> thread. Are
> >> you trying to call setText() from a different thread?
> >
> > setText(String text) is one of the few Swing methods that is thread-safe.
>
> It is one of the Swing methods that is incorrectly documented to be
> thread-safe.
>
>
>
> Christian
 
 
Hiran Chaudhuri





PostPosted: 2003-7-4 18:12:00 Top

java-programmer >> what i do wrong??? Hi, Dariusz.

This line will print the currently used tread's name:
System.out.println( "current thread: "+Thread.currentThread().getName() );

Hiran


".darek" <email***@***.com> schrieb im Newsbeitrag
news:email***@***.com...
> Hi!
>
> THANKS for you answers!
>
> How can I know, which thread will be used at the moment?
>
> Greetings
>
> Dariusz
>
>
> email***@***.com (Christian Kaufhold) wrote in message
news:<email***@***.com>...
> > Hello!
> >
> > Daniel Dyer <email***@***.com> wrote:
> >
> > > On Fri, 27 Jun 2003 12:19:59 GMT, dfdfd <email***@***.com> wrote:
> > >
> > >> All of your Swing gui method calls have to be done on the Swing event
> > >> thread. Are
> > >> you trying to call setText() from a different thread?
> > >
> > > setText(String text) is one of the few Swing methods that is
thread-safe.
> >
> > It is one of the Swing methods that is incorrectly documented to be
> > thread-safe.
> >
> >
> >
> > Christian


 
 
Michael Kutuzov





PostPosted: 2003-7-5 3:52:00 Top

java-programmer >> what i do wrong??? Hi Darek

".darek" <email***@***.com> ???????/???????? ? ???????? ?????????:
news:email***@***.com...
> Hi!
>
> THANKS for you answers!
>
> How can I know, which thread will be used at the moment?


Look at

java.awt.EventQueue
public static boolean isDispatchThread()

in JavaTM 2 Platform, Standard Edition, API Specification

I guess it's exactly what you're looking for ;)