Solved

Adding a Label

Posted on 2002-05-06
2
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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…

740 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