简体   繁体   English

如何将JLabel定位到Java GUI上的绝对位置

[英]How to locate JLabels to an absolute position on Java GUI

I have many JLabel s (which includes ImageIcon s) in a JPanel . 我在JPanel有很多JLabel (包括ImageIcon )。

And this JPanel is only a panel on the GUI; 而这个JPanel只是GUI上的一个面板; there are lots of other panels. 还有很多其他面板。

I want to place labels to the exact pixel coordinates on their JPanel container. 我想将标签放在JPanel容器上的精确像素坐标上。

How can I do that without using GroupLayout ? 如何在不使用GroupLayout情况下执行此GroupLayout

See Doing Without a Layout Manager (Absolute Positioning) in the Java tutorials. 请参阅Java教程中的“不使用布局管理器(绝对定位) ”。

Creating a container without a layout manager involves the following steps. 在没有布局管理器的情况下创建容器涉及以下步骤。

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

Either

Take a look at MigLayout, which allows you to do absolute positioning, it's not part of the JDK, but a seperate download . 看看MigLayout,它允许你做绝对定位,它不是JDK的一部分, 而是单独下载

It's very good as far as layout managers go and does absolute positioning, plus a whole load of other things. 就布局管理人员而言,这是非常好的绝对定位,以及其他一些东西。

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

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