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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:05:27+00:00 2026-05-31T07:05:27+00:00

I have put a label into my frame, but it refuses to move. SetBounds()

  • 0

I have put a label into my frame, but it refuses to move. SetBounds() is not working, and I get an improper alignment error if I put any argument past “Result” below that isn’t 0, 1, or 2, none of which put it in the correct place. Here’s where I declare the Label:

Label result = new Label(“Result.”, 3);

Here’s the SetBounds statement:

result.setBounds(0, 1500, 100, 20);

This program I am writing, I simply just want to have the user input 2 numbers, add them, and print the result using GUI components. The result is the label which refuses to change. The code of the entire program is below, and the program is still not done yet, but if you compile it, result is always stuck to the left and I want it to be at the same level as the TextFields. This problem is actually happening with the other labels, Help1, and Help2. Please don’t tell me I have to use swing! I dislike swing.

I have yet to change the event to where it adds the user inputs. I copied the event from a previous program.

The code: (Sorry for no comments, but it’s not a huge program)

import java.awt.*;
import java.awt.event.*;

public class MouseClick {
    TextField number1;
    TextField number2;

    public static void main(String[] args) {
        MouseClick MC = new MouseClick();
    }

    public MouseClick() {
        Frame f = new Frame("Addition Time!");
        Button button = new Button("Click Here To Add The Two Numbers.");
        button.setBounds(175, 250, 230, 30);
        button.addMouseListener(new MyMouseListener());
        f.add(button);
        Label help1 = new Label("Enter the first number below.");
        Label help2 = new Label("Enter the second number below.");
        Label exprsn1 = new Label("+", 0);
        Label exprsn2 = new Label("=", 0);
        Label result = new Label("Result.", 3);
        number1 = new TextField("TextField1", 100);
        number2 = new TextField("TextField2", 100);
        help1.setBounds(50, 80, 150, 20);
        help2.setBounds(250, 80, 150, 20);
        exprsn1.setBounds(00, 80, 30, 30);
        exprsn2.setBounds(00, 80, 30, 30);
        number1.setBounds(50, 100, 100, 20);
        number2.setBounds(250, 100, 100, 20);
        result.setBounds(0, 1500, 100, 20);
        f.add(number1);
        f.add(number2);
        f.add(help1);
        f.add(help2);
        f.add(result);
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                System.exit(0);
            }
        });
        f.setSize(600, 300);
        f.setVisible(true);
    }

    public class MyMouseListener extends MouseAdapter {
        public void mouseClicked(MouseEvent me) {
            String S = number1.getText();
            number2.setText(S);
        }
    }
}
  • 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-31T07:05:28+00:00Added an answer on May 31, 2026 at 7:05 am

    The error is because 3 is not an allowed value for parameter “alignment” in the constructor

    Label(String text, int alignment) 
    

    Are you getting confused with TextField() which has a similar constructor?

    TextField(String text, int columns)
    

    The reason the label is not appearing in the correct location is because you’ve not specified your using null layout explicitly. You need this line:

    public MouseClick() {
        Frame f = new Frame("Addition Time!");
        f.setLayout(null);  // add this line
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure how to put this best into a title, but this is
I have a label into which I am going to put content of different
I have a TableLayoutPanel and every time I put a label into one of
i have put fckeditor in jsp page. I want to get the value whatever
I have put some Console.WriteLine calls in to test, but they aren't appearing in
I have a Window where I have put a Frame. I would like to
I'm working on a project that requires GUI, but I have no experience with
im trying to change the text of a label from a class but have
I have successfully put together 3three Histograms into 1one Plot with the Lattice package.
I'm using a PHP form to put values into a table I have. Everything

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.