Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding a Label

Posted on 2002-05-06
2
Medium Priority
?
148 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 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

963 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