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 9138371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:14:51+00:00 2026-06-17T09:14:51+00:00

The code has been simplified considerably as to only highlight the issue. I’m not

  • 0

The code has been simplified considerably as to only highlight the issue. I’m not certain this is the best way to approach this problem either.

I’m attempting to make an object that can have any single swing component and a set of generic methods to edit the component. In this case having a method which sets the components text if the component is a JLabel and returning whether it was successful.

package table;

import java.awt.Component;

public class CompTest
{
    private Component comp;
    public CompTest(Component C)
    {
        comp=C;
    }

    public boolean setText(String S)
    {
        if(comp instanceof javax.swing.JLabel)
        {
            comp.setText(S); //error
            return true;
        }
        return false;
    }
}

The object would be created similarly to;

...
CompTest comp1=new CompTest(new javax.swing.JLabel());
...

I’m using the Netbeans IDE 7.2, and gives me an error for the line containing “//error” (in the first codeblock);

cannot find symbol
 symbol: method setText(String)
 location: variable comp of type Component

How can I fix the issue, and if there is none (which I doubt) how do I get Netbeans to play nice?

  • 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-06-17T09:14:52+00:00Added an answer on June 17, 2026 at 9:14 am

    The class Component does not have a method called setText.

    You have to cast comp first to a JLabel and then can call the method, e.g.:

    ((javax.swing.JLabel)comp).setText(S);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Once code has been written, the only way I know of to view the
EDIT : the code has been trimmed down to contain only what is necessary
In this very simplified and minimized example click event handler has been defined for
Consider the code below (which has been simplified). I have a service class that
The following code is a simplified example of an issue I am seeing. This
I know this question has been asked before but the solutions did not work
Code has been amended and now it works as follows when you click on
So my code has been working fine, and I was added some extra functionality
We are looking to redirect users to different pages after code has been executed,
SOLVED. Code has been edited to reflect solution. Given the following GridView : <asp:GridView

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.