it wont move!

?

_.-=

Hi!

I have a simple little program here using AWT for which I'm not using any
layout managers, but instead am setting the position of the components
manually.

Now, the problem is - I can't move the button away from the left edge of the
frame. I tried using setBounds: "button1.setBounds(43,170,35,20);"
Which should mean that the button should be painted at coordinates (43,170)
and extend to (43+35,170+20). On running the code, the button is still at
the left edge of the frame!!!!


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



class BettEdit extends Frame{

Frame window1 = new Frame("window1");
Label label1 = new Label("BettEdit");
Button button1 = new Button("Save");
TextArea text1 = new TextArea();


public static void main (String args[]) {
ParWindow win1 = new ParWindow();
}

BettEdit() {
//label1.setBounds(10,50,150,20);
button1.addActionListener(new ActionHandler1());
button1.setBounds(43,170,35,20);
text1.setBounds(3,90,250,150);

window1.addWindowListener(new WindowHandler());
window1.pack();
window1.setSize(600,400);
window1.show();
//window1.add(label1);
window1.add(button1);
window1.add(text1);
}

class WindowHandler extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}

class ActionHandler1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
label1.setText(text1.getText());
}
}



}
 
L

Lee Fesperman

_.-= said:
Hi!

I have a simple little program here using AWT for which I'm not using any
layout managers, but instead am setting the position of the components
manually.

Now, the problem is - I can't move the button away from the left edge of the
frame. I tried using setBounds: "button1.setBounds(43,170,35,20);"
Which should mean that the button should be painted at coordinates (43,170)
and extend to (43+35,170+20). On running the code, the button is still at
the left edge of the frame!!!!

All AWT containers have a default layout manager. If you don't want to use a layout
manager, you need to explicitly set a null layout manager, though that is very rarely a
good idea.
 
J

Jon A. Cruz

Jacob said:
As far as I recall a null-layout is an
undocumented feature.

No.

It is just usually a very bad idea that is used in place of a better
(and usually less work in the long run) 'correct' solution.


Using absolution positioning is usually a very very bad shortcut, and
ends up inflicting all sorts of pain.


Instead of just kludging things together, take a little time to learn
layout managers and suddenly all will work so much better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top