Solved

Adding a Label

Posted on 2002-05-06
2
142 Views
Last Modified: 2010-05-18
How do I specify explicitly where I can add a label?

For example, if I have an applet 300x500, how can I put it at  150, 300
0
Comment
Question by:djmajiktc
2 Comments
 
LVL 2

Accepted Solution

by:
mzimmer74 earned 50 total points
ID: 6991979
Well, one way is to set your layout of your applet to null (setLayout(null)) and then set bounds on your label with:

label.setBounds(new Rectangle(150,300,width,height));

width and height are how big you want your label to be.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6992022
you don't need to add the label, you can do something like this:

public class MsgTest extends java.applet.Applet {
   
    private String msg;
 
    public void init()
        {
          msg = "This should go at 150, 300";
      }

      public void paint(Graphics g) {
           if (msg != null && !msg.trim().equals("")) {
                g.drawString(msg, 150, 300);
           }    
      }
     
}

All you have to do is set msg to null or "" and call repaint() to make it go away

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 89
JavaScript/Java - Changing an image background color 4 65
Android development question 2 34
Desingning Refactoring existing code 2 24
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now