TCLUG Development Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG-DEVEL:175] Absolute positioning in Java AWT?



Bob Tanner wrote:
> 
> Does AWT allow for absolute positioning?

Yes, it does.  However, if you resize the window, you may lose the
component because that position.

Look at any of the drawImage methods on the Graphics object that takes a
x,y coordinate.  For example

* @param    img    the specified image to be drawn.
* @param    x      the <i>x</i> coordinate.
* @param    y      the <i>y</i> coordinate.
* @param    bgcolor the background color to paint under the
*                         non-opaque portions of the image.
* @param    observer    object to be notified as more of 
*                          the image is converted.
* @see      java.awt.Image
* @see      java.awt.image.ImageObserver
* @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image,
int, int, int, int, int)
* @since    JDK1.0
*/
public abstract boolean drawImage(Image img, int x, int y, Color
bgcolor, ImageObserver observer);

> 
> I have a basic graphic and I want to put a TextField in the upper-right corner
> of the graphic.
> 

the code would look like this:

g.drawImage(t_textField, 0, 600, Color.WHITE, this)

where t_textField is an instance of the TextField, 
0, 600 is the absolute position, 
Color.WHITE is the background
this refers to the Panel, Applet, whatever that implements ImageObserver

> No matter what I do I cannot force the TextField into the upper-right corner.
> 
> I am using g.drawImage() to paint the graphic onto the component. I then try
> to add the TextField, but it always centers it no matter what Layout I use.

use a null layout manager, i.e. setLayout(null);

> 
> This took me 5 minutes to do in X. I see why people complained about Java's
> GUI.

-- 
Perry Hoekstra
Talent Software Services
dutchman@mn.uswest.net

"I don't see much sense in that," said Rabbit.
"No," said Pooh humbly, "there isn't. But there was going to be when I
began it. It's just that something happened to it along the way."