Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6242423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:57:09+00:00 2026-05-24T11:57:09+00:00

I am currently working on a Swing Applet, and am having issues referencing my

  • 0

I am currently working on a Swing Applet, and am having issues referencing my custom AWT Canvas component (very simple extended class) in other class functions, such as with any other component (i.e. button) normally created with Netbean (7.0)’s designer.

My custom canvas element I add here, I was sure this would be the appropriate place (especially after all other generated components were just created in the same area)

public void init() {
    try {
        java.awt.EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                initComponents();

                CustomCanvas myCan = new CustomCanvas();
                myCan.setBounds(100, 100, 200, 200);
                getContentPane().add(myCan);
          ...

However, unlike the generated components, I cannot access them by name and cannot seem to access them through other means (this.myCan) either. I have set up a sample function that will handle a (generated) button on the Swing form to manipulate the previously instantiated myCan component:

private void btnManipCanvasActionPerformed(java.awt.event.ActionEvent evt) {
  //Essentially Was wanting to call something here such as myCan.getGraphics().setRect...
}

Do you know of a way to access myCan there? Am I supposed to place custom initializations of components in a different area so they can be publicly accessed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:57:10+00:00Added an answer on May 24, 2026 at 11:57 am

    Just make the canvas an instance variable, as (I guess) all the other components created by the Netbeans designer:

    private CustomCanvas myCan;
    
    public void init() {
    try {
        java.awt.EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                initComponents();
    
                myCan = new CustomCanvas();
                myCan.setBounds(100, 100, 200, 200);
                getContentPane().add(myCan);
                // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a (rather large) pet project of mine , a Swing
I'm working on a Swing application (currently running on Java 1.6 update 11) which
I`m currently working out the design for simple graphic editor, who support trivial operations
Hey all, I'm currently working on a Java Swing application and I was looking
I am currently working on a SWING frame with a JScrollPane (including a JComponent),
I'm currently working on a Swing app and I've got a few JTextAreas that
I am currently working on a set of custom controls for a product of
I'm working on building a chess game in Java, and I'm currently having a
I am currently working with swing applications.For a developer ,it is most important that
I am programming in Java, using Swing. I am currently working with an application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.