简体   繁体   English

自动调整jframe组件的大小

[英]Resizing components of jframe automatically

Am writing a code on swings and am using null layout so that i can put j components anywhere i like by using set Bounds But when i maximize the J Frame my components will be static. 我在秋千上编写代码,并使用空布局,这样我就可以通过使用set Bounds将j组件放置在任何地方,但是当我最大化J Frame时,我的组件将是静态的。

How can i make components to move automatically. 我如何使组件自动移动。 Please help me its important. 请帮助我,它很重要。

And i have to use null layout only cant use any other layout because i have to put so many components to there specific place. 而且我必须使用null布局,而不能使用任何其他布局,因为我必须将许多组件放置到特定位置。

    public class ScreenResize extends JFrame{
    private static JButton b;
    ScreenResize(){

    JFrame.setDefaultLookAndFeelDecorated(true);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    int frameWidth = 200;
    int frameHeight = 100;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((int) screenSize.getWidth() - frameWidth, 0, frameWidth, frameHeight);
    setVisible(true);
    b=new JButton();
    b.setBounds(50,50,40,20);
    add(b);

    }
    public static void main(String[] args) {
    new ScreenResize();
    }
    }   

Thanks. 谢谢。

You won't be able to do that unless you want to reprogram what would essentially be the other layouts like BorderLayout, GridLayout, and so on. 除非您想重新编程本质上将是诸如BorderLayout,GridLayout等其他布局的程序,否则您将无法做到这一点。 So the solution for this is to not use a null layout and use a combination of other layouts nested together. 因此,解决方案是不使用空布局,而使用嵌套在一起的其他布局的组合。

Here's a link to get started on what the other specific layouts can do for you . 这是一个链接,可让您开始了解其他特定布局可以为您提供的服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM