XY Layout JAVA

前端 未结 4 1200
刺人心
刺人心 2021-01-07 03:46

is there any sort of XY-Layout to Java?

So I can set a Button at the X and Y cordinate and that it is suppose to be that big etc.... Because this border layout and

4条回答
  •  渐次进展
    2021-01-07 04:47

    If you really want to do this, use

    setLayout(null);
    

    on the component you're putting things into, then use

    setBounds(x, y, width, height);
    

    to set the absolute coordinates of the elements. Example:

    setLayout(null);
    JButton myButton = new JButton("Do Stuff");
    add(myButton);
    myButton.setBounds(30, 30, 100, 30);
    

    However, the resulting GUI will look non-standard, won't be resizable, and if it's of any complexity, will be a pain to maintain.

    I know that layouting is frustrating, but in the end you will be better off using a combination of BorderLayouts and FlowLayouts, orGridBagLayout - or an IDE interface builder like Eclipse's or Netbeans'.

提交回复
热议问题