• Post Reply Bookmark Topic Watch Topic
  • New Topic

Function Issue  RSS feed

 
Barclay Berger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm try to use a function to set some text and set the icons of various
labels and I thought I could send the labelnames to the function and
use it to set them but I'm having issues. It doesn't work all the time.
It randomly sets the text of various labels or sometimes none at all.
Can't figure it out. Here is what I have, I've very new to java so I'm
obviously doing something wrong.

public void jButton6_actionPerformed(ActionEvent e) {
GetThumb(this.jLabel6, this.jTextField6);



}


public void GetThumb(JLabel labelNo, JTextField fieldNo) {
labelNo.setIcon(thumbnail);
fieldNo.setText(name);
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Please post rather more code.

Are you adding an ActionListener to your button6?

Have you got this sort of call?
What are you doing in your getThumb method? Where do you get the thumbNail from? Where do you get the name from?
 
Barclay Berger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I have the listener, I was trying to simplify things here and seeing if I am implementing passing of labels and textfields to the function. I have a problem with it not getting the name correctly. if I debug the labelNo & fieldNo I get null. I don't think I'm passing and using correctly. Let me simplify even further, the fieldNo.setText("hello"); randomly works and sometime uses the wrong field.

public void jButton6_actionPerformed(ActionEvent e) {
GetThumb(this.jTextField6);
}
public void GetThumb(JTextField fieldNo) {
fieldNo.setText("hello");
}
button6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { jButton6_actionPerformed(e);
}
});
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> It doesn't work all the time.
> It randomly sets the text of various labels or sometimes none at all.

you must have a random element in your (unposted) code.
post a sample program that demonstrates the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!