You need to spend some time looking at how layout managers work. The GridLayout will do exactly what you are seeing. Using FlowLayout or BoxLayout will end up sizing the button to fit nicely around its label.
Bill Squires
Tim Nicholson wrote:
Hi list,I am trying to master Buttons -- and have been having a few problems.First I have 1 or 2 questions :-1) What is the difference between a Button and a JButton ? Or in the same way, between a Frame and a JFrame ?Button seems to be a class in the java.awt library. But what about if you put a "J" in front of it ?2) My problem at the moment is trying to get my Button in the code below to match up to my expectations. I managed to get a GUI going and to incorporate a Button into it -- but the problem is that the Button takes up half of the GUI (the top half). I wanted a nice small Button and in a place where I could choose to put it. Instead what I got was this huge thing that takes up half the screen and I have no say as to where I would like to put it.Can someone give me some pointers as to how I can modify my code to achieve what I want ?//--------------------------------------------------------------------import java.awt.*;
import java.awt.event.*;public class File1 extends Frame implements ActionListener{
//button is a GUI component
//GUI (Graphic User Interface
private Button setbutton;
public File1() {
setLayout(new GridLayout(3,2));
setbutton = new Button("SET");
add(setbutton);
setbutton.addActionListener(this);
setSize(300,100);
setTitle("Kitchen System");
setVisible(true);
}//end of constructor//---------------------------------------------------------------
//actionPerformed
//---------------------------------------------------------------public void actionPerformed (ActionEvent e) {
Button b = (Button)e.getSource();
if (b == setbutton)
{
}//end of if
}//end of actionPerf
public static void main(String [] args)
{
new File1();
}}//end of class
---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
http://www.sys-con.com/fusetalk
