http://wenwen.soso.com/z/q428179812.htm?ch=ww.gr.dcltw.title&pid=ww.gr.dcltw.title。谢谢。
如果整体的宽度不变的话,也可以使用绝对布局就像下面这样,再美化一下就可以了
package com.tur.demo;
import info.clearthought.layout.TableLayout;
import javax.swing.*;
import java.awt.*;
public class SwingDemo extends JFrame {
public SwingDemo() {
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
double[] columnSize = {p, f, p, p};
double[] rowSize = {p, p, p, p, p};
Container container = getContentPane();
container.setLayout(new TableLayout(columnSize, rowSize));
JLabel labelIcon = new JLabel("Label");
labelIcon.setPreferredSize(new Dimension(50, 50));
labelIcon.setBackground(Color.BLUE);
labelIcon.setOpaque(true);
container.add(labelIcon, "0, 0, 0, 1");
container.add(new JLabel("发送离线文件"), "1, 0, 3, 0, l, c");
container.add(new JLabel("文件名字"), "1, 1, 3, 1, l, c");
container.add(new JProgressBar(0, 100), "0, 2, 3, 2");
container.add(new JLabel("速度: 229K/s"), "0, 3, 2, 3, l, c");
container.add(new JLabel("229.00K/324.00K"), "2, 3, 3, 3, r, c");
container.add(new JLabel("取消"), "3, 4, 3, 4, r, c");
container.add(new JLabel("发送离线文件"), "0, 4, 2, 4, r, c");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setSize(250, getSize().height); // 设置窗口的大小
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
JFrame frame = new SwingDemo();
// Grid.showGrid(frame.getContentPane());