Skip to main content



      Home
Home » Newcomers » Newcomers » JLabel reference
JLabel reference [message #256531] Fri, 16 May 2008 15:32 Go to next message
Eclipse UserFriend
Originally posted by: web02.comcast.net

I am a newby to VEP. I got it loaded finally and to play, I added a
jButton and a jLabel to the default pane then created a button click event.

The code and some of the auto generated mouse clicked code looks like:

// Globals
private JPanel jContentPane = null;
private JButton jButton = null;
private JLabel jLabel = null;

.
.
.
// Buried in method private "JButton getJButton()"

public void mouseClicked(java.awt.event.MouseEvent e) {
System.out.println("mouseClicked()"); // TODO Auto-generated Event stub
mouseClicked()
jLabel.text="XXX"; // <-- MY CODE
}


If I try to reference jLabel.text in this method I get an error stating
"jLabel.texr is not visible".

Can someone explain what is happening here. I do not see a scope problem,
but obviously something is happening that I don't understand.

Thanx,
Bill
Re: JLabel reference [message #256535 is a reply to message #256531] Fri, 16 May 2008 16:43 Go to previous messageGo to next message
Eclipse UserFriend
The "text" field is private. You can't access it outside of the class
itself.

Use the getText() and setText(String) methods instead.

HTH,

Wayne

On Fri, 2008-05-16 at 19:32 +0000, web wrote:
> I am a newby to VEP. I got it loaded finally and to play, I added a
> jButton and a jLabel to the default pane then created a button click event.
>
> The code and some of the auto generated mouse clicked code looks like:
>
> // Globals
> private JPanel jContentPane = null;
> private JButton jButton = null;
> private JLabel jLabel = null;
>
> .
> .
> .
> // Buried in method private "JButton getJButton()"
>
> public void mouseClicked(java.awt.event.MouseEvent e) {
> System.out.println("mouseClicked()"); // TODO Auto-generated Event stub
> mouseClicked()
> jLabel.text="XXX"; // <-- MY CODE
> }
>
>
> If I try to reference jLabel.text in this method I get an error stating
> "jLabel.texr is not visible".
>
> Can someone explain what is happening here. I do not see a scope problem,
> but obviously something is happening that I don't understand.
>
> Thanx,
> Bill
>
Re: JLabel reference [message #256539 is a reply to message #256535] Fri, 16 May 2008 16:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: web02.comcast.net

Thanks, I tried it and that error went away. Now, I am getting:

jLabel.setText cannot be resolved or is not a field.

The variable is the correct name. It appears to be in scope.
Re: JLabel reference [message #256547 is a reply to message #256539] Fri, 16 May 2008 16:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: web02.comcast.net

Thanks for your help. I got it.

For some reason. if I enter "jlabel.", I don't get the available method
list.
Re: JLabel reference [message #256551 is a reply to message #256547] Fri, 16 May 2008 17:14 Go to previous messageGo to next message
Eclipse UserFriend
jlabel isn't defined. I think you mean jLabel. Java is case-sensitive.

After you type "jlabel", hit ctrl-space. Content assist will correct it
for you.

Wayne

On Fri, 2008-05-16 at 20:58 +0000, web wrote:
> Thanks for your help. I got it.
>
> For some reason. if I enter "jlabel.", I don't get the available method
> list.
>
Re: JLabel reference [message #256561 is a reply to message #256539] Fri, 16 May 2008 17:59 Go to previous message
Eclipse UserFriend
setText is not a field. it's a method. You need the parens. It's a Java
thing.

jLabel.setText("Hello there");

HTH,

Wayne

On Fri, 2008-05-16 at 20:53 +0000, web wrote:
> Thanks, I tried it and that error went away. Now, I am getting:
>
> jLabel.setText cannot be resolved or is not a field.
>
> The variable is the correct name. It appears to be in scope.
>
>
>
Previous Topic:Using command line options for Eclipse methods
Next Topic:Trigonometry
Goto Forum:
  


Current Time: Thu May 01 08:48:46 EDT 2025

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

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

Back to the top