在面板南侧的中心添加标签?

时间:2016-04-29 02:24:42

标签: java swing layout-manager

下面的代码将标签添加到面板的左侧,当我使用带有标签的设置位置时,位置不会改变。有没有办法让标签位于面板的中央,而不需要额外的面板?

编辑:JFrame有一个BorderLayout,并将面板添加到CENTER

JPanel pnl = new JPanel();
pnl.setPreferredSize(new Dimension(500,500));
JLabel lbl = new JLabel("label");
pnl.setLayout(new BorderLayout());
pnl.add(lbl, BorderLayout.SOUTH);

1 个答案:

答案 0 :(得分:2)

您似乎需要将标签的文本对齐设置为中心面板? 如果是这样,试试这个:

<domain type="kvm" xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">
  <name>i-win2003/name>
  <os>
    <type>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
  </features>
  <clock offset="localtime"/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <vcpu current="1">1</vcpu>
 <memory>2097152</memory>
  <currentMemory>2097152</currentMemory>
  <devices>
    <disk device="disk" type="file">
      <driver name="qemu" type="qcow2"/>
      <source file="/root/i-win2003/snap.qcow2"/>
      <target bus="virtio" dev="vda"/>
    </disk>
    <disk type='file' device='cdrom'>
      <source dev=''/>
      <target dev='hdc' bus='ide'/>
    </disk>
    <serial type="pty">
      <source path="/dev/pts/1"/>
      <target port="0"/>
    </serial>
   <interface type='bridge'>
      <mac address='fa:16:3e:81:68:b4'/>
      <source bridge='eucabr'/>
      <model type='virtio'/>
      <driver name='qemu'/>
      <alias name='net0'/>
    </interface>
    <channel type='unix'>
      <source mode='bind'/>
      <target type='virtio' name='org.qemu.guest_agent.0'/>
    </channel>
    <controller type="usb" index="0" model="ich9-ehci1"/>
    <controller type="usb" index="0" model="ich9-uhci1"/>
    <controller type="usb" index="0" model="ich9-uhci2"/>
    <controller type="usb" index="0" model="ich9-uhci3"/>
    <input type="tablet" bus="usb"/>
    <input type="mouse" bus="ps2"/>
    <graphics type="vnc" port="-1" autoport="yes" keymap="en-us" listen="0.0.0.0"/>
  </devices>
  <qemu:commandline>
  </qemu:commandline>
</domain>

结果:

Result