Solved

How to set width and height for JButton ?

Posted on 2001-07-03
3
2,559 Views
Last Modified: 2012-06-27
By default, the JButton's size is according to the
text size or the image size. Is there anyway to set
the width and height for JButton ?
0
Comment
Question by:andric
[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
3 Comments
 

Author Comment

by:andric
ID: 6251109
Urgent!
0
 
LVL 1

Accepted Solution

by:
chris_kabuki earned 100 total points
ID: 6251184
JButton myButton = new JButton();
// Do all your set's etc here

// i.e. x-coord = 0, y-coord = 0, width = 100, height = 20
myButton.setBounds(0, 0, 100, 20);
0
 

Author Comment

by:andric
ID: 6251460
Thanks. It's works ! But, you must set the layout to null for where the button reside. Otherwise, the setting will not take place.

-----------------------------------------------------------
JPanel p = new JPanel();
// Set layout to null
p.setLayout(null);

JButton myButton = new JButton();
// Do all your set's etc here

// i.e. x-coord = 0, y-coord = 0, width = 100, height = 20
myButton.setBounds(0, 0, 100, 20);

p.add(myButton);
-----------------------------------------------------------
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…
Suggested Courses

617 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