【问题标题】:Use a layout in place of a component使用布局代替组件
【发布时间】:2015-10-19 11:23:38
【问题描述】:

我想创建一个带有 BorderLayout 的主窗口框架,其中包含其他布局作为其组件。

我怎样才能将FlowLayout 添加到我的BorderLayoutNORTH 位置?

【问题讨论】:

标签: java swing awt layout-manager border-layout


【解决方案1】:

这里有一个小程序向你展示:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
    public class LayoutExample {
        public static void main (String[] args) {
            JFrame frame = new JFrame("Frame with BorderLayout");
            frame.setLayout(new BorderLayout());
            JPanel flow = new JPanel();
            JLabel label = new JLabel("This is a flowlayout.");
            flow.setBorder(new LineBorder(Color.BLACK));
            flow.setLayout(new FlowLayout());
            flow.add(label);

            frame.add(flow, BorderLayout.NORTH);
            frame.setSize(300,300);
            frame.setVisible(true);
       } 
    }

最后是这样的:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-09
    • 1970-01-01
    • 2013-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多