如何使用setLocation移动组件 [英] how to use setLocation to move componets

查看:260
本文介绍了如何使用setLocation移动组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用setLocation将此应用程序的组件设置到设置的位置,到目前为止,我还无法移动组件.还有更多代码,但大多数情况下会调用并设置此代码.有什么想法吗?

I'm trying to set the components of this application to a set location using setLocation so far i haven't been able to move the components. There is more code but its get calling and setting this code for the most part. any ideas?

import javax.swing.*;



public class HangmanPanel extends JPanel {
    private static final long serialVersionUID = -5793357804828609325L;

    public HangmanPanel(){

        JLabel heading = new JLabel("Welcome to the Hangman App");
        JButton Button = new JButton("Ok");
        //Button.addActionListener();   
        JLabel tfLable = new JLabel("Please Enter a Letter");
        JTextField text = new JTextField(10);

        String input = text.getText();
        heading.setLocation(50, 20);
        tfLable.setLocation(20, 100);
        text.setLocation(320, 50);
        Button.setLocation(230, 100);

        this.add(heading);
        this.add(tfLable);
        this.add(text);
        this.add(Button);
    }
}

推荐答案

您不应使用setLocation()来布局Swing组件,最好使用Layout.请查看这些布局教程.

You should not use setLocation() to layout Swing components, it is much better to use a Layout. Please have a look at these Layout Tutorials.

这篇关于如何使用setLocation移动组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆