aspose file tools
The moose likes IDEs, Version Control and other tools and the fly likes Netbeans 4.0 - private/public access problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Reply Bookmark "Netbeans 4.0 - private/public access problem" Watch "Netbeans 4.0 - private/public access problem" New topic
Author

Netbeans 4.0 - private/public access problem

Steve Schowiak
Greenhorn

Joined: Oct 21, 2002
Posts: 20
I want to change the text of a jLabel in another class at runtime from within a Java application. That class is declared as public:

public class bank extends javax.swing.JPanel { ...

I am getting this compile error:

C:\Documents and Settings\Steve\J95\src\j95\main.java:18: bankJLabel has private access in j95.bank this.bank1.bankJLabel.setText("1");

This is the code in question:

public main() {
initComponents();
this.bank1.bankJLabel.setText("1");
// so on and so forth ...
}

NB 4.0 sets some variables as private at the bottom of the code in the main application class, but I'm not sure if this has anything to do with the problem:

private j95.bank bank0;
private j95.bank bank1;
private j95.bank bank2; ... etc.

The IDE won't let me change it to public so the jLabel can be accessed. I'm not sure if this is a problem with the IDE or me. Probably me . Can anybody offer a clue? The complete listing of the main application code follows. The application and other classes otherwise run fine. Thanks!:



I am not insane. The voices in my head told me so.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26184
    
  66

Steve,
I haven't used Netbeans, but their generated code is pretty clear. You definitely shouldn't mess with the generated code or it will not work in the future.

Where is the "bank" class? Can you add a getter method to it? In general, it is better to use getter/setter methods than try to make the variables public.

Also, two comments:
1) Class names are capital by convention. So "bank" should be "Bank".
2) Main is a bit confusing for a class name.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Steve Schowiak
Greenhorn

Joined: Oct 21, 2002
Posts: 20
I figured it out. If you right-click on the variable declarations at the bottom of the code, you can change public/private access.

Thanks anyway!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Netbeans 4.0 - private/public access problem
 
Similar Threads
How can i display minimize and iconifiable button in JInternalFrame
returning String from ActionPerformed
Insert an image in JScrollPane
JMenubar/Jmenu/JMenuItem does not work
Whatz the problem