在JPanel中手动定位JComponent [英] Manually position JComponent inside JPanel

查看:74
本文介绍了在JPanel中手动定位JComponent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式将JLabel移到JPanel中的特定位置.我已经尝试过 setLocation(int x,int y),但是它不起作用.我试图不使用任何布局管理器.

I want to programmatically move my JLabel to a specific location inside my JPanel. I have tried setLocation(int x, int y), but it doesn't work. I am trying to not use any layout manager.

推荐答案

这是一个很棒的教程,介绍如何在不使用布局管理器的情况下对组件进行布局.

Here is a great tutorial on how to layout your components without using a layout manager.

http://java.sun.com/docs/books/tutorial/uiswing/layout/none.html

在没有布局管理器的情况下创建容器涉及以下步骤.

Creating a container without a layout manager involves the following steps.

  1. 通过调用 setLayout(null)将容器的布局管理器设置为null.
  2. 为容器的每个子级调用Component类的 setbounds 方法.
  3. 调用Component类的 repaint 方法.
  1. Set the container's layout manager to null by calling setLayout(null).
  2. Call the Component class's setbounds method for each of the container's children.
  3. Call the Component class's repaint method.

这篇关于在JPanel中手动定位JComponent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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