Archived

This topic is now archived and is closed to further replies.

[java] Anybody know of a way to layout the components in an applet using coordinates?

This topic is 5380 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I mean, is there a way to give a set of coordinates to draw a button or label or textfield or whatever to the screen? Gridbag is the closest I can get, but it is VERY tedious and difficult. There has to be an easier way. I don''t care if it gets all screwed up if the user resizes the screen or what their resolution is, because I will give a warning about that.

Share this post


Link to post
Share on other sites
i havent done java in awhile, but im pretty sure if you want you can have absolute control over the placement of things. CHeck out the api docs

Share this post


Link to post
Share on other sites
no its a width and height:


  
void setBounds(int x, int y, int width, int height)
Moves and resizes this component.


straight from the docs -- java.awt.component has a lot of methods you may find useful.

Share this post


Link to post
Share on other sites
yeah...I tried that, and had it all set up. but it doesn''t show anything when I run the applet. it''s blank. if I take out the ''setLayout(null)'', it shows everything I add, but it resorts to flowlayout even though I set the boundaries of each object. I think I''ll just stick to gridBagLayout or whatever. I know it works, it''s just time consuming.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
try:


  
setVisible(true); // this is probably supposed to be defaulted too


setEnabled(true); // this is supposed to be by default



I assume you are already using the add method to add components to the ?? (other component, like i said its been awhile).

Matt

Share this post


Link to post
Share on other sites
This is how I did it and it worked fine.

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

public class TestApplet extends Applet {
Button b1=new Button("Button 1");
Button b2=new Button("Button 2");
Button b3=new Button("Button 3");
Button b4=new Button("Button 4");

public void init() {
setLayout(null);
add(b1);
add(b2);
add(b3);
add(b4);
b1.setBounds(0,0,200,30);
b2.setBounds(40,40,30,30);
b3.setBounds(20,170,300,30);
b4.setBounds(370,20,130,60);
}
}




First make it work,
then make it fast.

--Brian Kernighan

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites