边界布局

  • 一、简单引导
  • 二、流程图
  • 三、例子
    • 1. 情况1
      • (1)源码A
      • (2)源码A运行效果
    • 2. 情况2
      • (1)源码B
      • (2)源码B运行效果
    • 3. 情况3
      • (1)源码C
      • (2)源码C运行效果
  • 四、定位日期

一、简单引导

边界布局,各组件(这里用“按钮”)分布在窗体的东、西、南、北边,除此中间部分也一同归并到边界布局。附图效果便一目了然,如下图:

二、流程图

  • 从创建窗体到最后边界布置的流程图。本篇的用“按钮”展示效果。详细窗体内容可以浏览同专栏的博文。
#mermaid-svg-w6aDtxxZTjbuvNMz .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .label text{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .node rect,#mermaid-svg-w6aDtxxZTjbuvNMz .node circle,#mermaid-svg-w6aDtxxZTjbuvNMz .node ellipse,#mermaid-svg-w6aDtxxZTjbuvNMz .node polygon,#mermaid-svg-w6aDtxxZTjbuvNMz .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-w6aDtxxZTjbuvNMz .node .label{text-align:center;fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .node.clickable{cursor:pointer}#mermaid-svg-w6aDtxxZTjbuvNMz .arrowheadPath{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-w6aDtxxZTjbuvNMz .flowchart-link{stroke:#333;fill:none}#mermaid-svg-w6aDtxxZTjbuvNMz .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-w6aDtxxZTjbuvNMz .edgeLabel rect{opacity:0.9}#mermaid-svg-w6aDtxxZTjbuvNMz .edgeLabel span{color:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-w6aDtxxZTjbuvNMz .cluster text{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-w6aDtxxZTjbuvNMz .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-w6aDtxxZTjbuvNMz text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-w6aDtxxZTjbuvNMz .actor-line{stroke:grey}#mermaid-svg-w6aDtxxZTjbuvNMz .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-w6aDtxxZTjbuvNMz #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .sequenceNumber{fill:#fff}#mermaid-svg-w6aDtxxZTjbuvNMz #sequencenumber{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz #crosshead path{fill:#333;stroke:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .messageText{fill:#333;stroke:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-w6aDtxxZTjbuvNMz .labelText,#mermaid-svg-w6aDtxxZTjbuvNMz .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-w6aDtxxZTjbuvNMz .loopText,#mermaid-svg-w6aDtxxZTjbuvNMz .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-w6aDtxxZTjbuvNMz .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-w6aDtxxZTjbuvNMz .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-w6aDtxxZTjbuvNMz .noteText,#mermaid-svg-w6aDtxxZTjbuvNMz .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-w6aDtxxZTjbuvNMz .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-w6aDtxxZTjbuvNMz .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-w6aDtxxZTjbuvNMz .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-w6aDtxxZTjbuvNMz .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz .section{stroke:none;opacity:0.2}#mermaid-svg-w6aDtxxZTjbuvNMz .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-w6aDtxxZTjbuvNMz .section2{fill:#fff400}#mermaid-svg-w6aDtxxZTjbuvNMz .section1,#mermaid-svg-w6aDtxxZTjbuvNMz .section3{fill:#fff;opacity:0.2}#mermaid-svg-w6aDtxxZTjbuvNMz .sectionTitle0{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .sectionTitle1{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .sectionTitle2{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .sectionTitle3{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-w6aDtxxZTjbuvNMz .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz .grid path{stroke-width:0}#mermaid-svg-w6aDtxxZTjbuvNMz .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-w6aDtxxZTjbuvNMz .task{stroke-width:2}#mermaid-svg-w6aDtxxZTjbuvNMz .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz .taskText:not([font-size]){font-size:11px}#mermaid-svg-w6aDtxxZTjbuvNMz .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-w6aDtxxZTjbuvNMz .task.clickable{cursor:pointer}#mermaid-svg-w6aDtxxZTjbuvNMz .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-w6aDtxxZTjbuvNMz .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-w6aDtxxZTjbuvNMz .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-w6aDtxxZTjbuvNMz .taskText0,#mermaid-svg-w6aDtxxZTjbuvNMz .taskText1,#mermaid-svg-w6aDtxxZTjbuvNMz .taskText2,#mermaid-svg-w6aDtxxZTjbuvNMz .taskText3{fill:#fff}#mermaid-svg-w6aDtxxZTjbuvNMz .task0,#mermaid-svg-w6aDtxxZTjbuvNMz .task1,#mermaid-svg-w6aDtxxZTjbuvNMz .task2,#mermaid-svg-w6aDtxxZTjbuvNMz .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-w6aDtxxZTjbuvNMz .taskTextOutside0,#mermaid-svg-w6aDtxxZTjbuvNMz .taskTextOutside2{fill:#000}#mermaid-svg-w6aDtxxZTjbuvNMz .taskTextOutside1,#mermaid-svg-w6aDtxxZTjbuvNMz .taskTextOutside3{fill:#000}#mermaid-svg-w6aDtxxZTjbuvNMz .active0,#mermaid-svg-w6aDtxxZTjbuvNMz .active1,#mermaid-svg-w6aDtxxZTjbuvNMz .active2,#mermaid-svg-w6aDtxxZTjbuvNMz .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-w6aDtxxZTjbuvNMz .activeText0,#mermaid-svg-w6aDtxxZTjbuvNMz .activeText1,#mermaid-svg-w6aDtxxZTjbuvNMz .activeText2,#mermaid-svg-w6aDtxxZTjbuvNMz .activeText3{fill:#000 !important}#mermaid-svg-w6aDtxxZTjbuvNMz .done0,#mermaid-svg-w6aDtxxZTjbuvNMz .done1,#mermaid-svg-w6aDtxxZTjbuvNMz .done2,#mermaid-svg-w6aDtxxZTjbuvNMz .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-w6aDtxxZTjbuvNMz .doneText0,#mermaid-svg-w6aDtxxZTjbuvNMz .doneText1,#mermaid-svg-w6aDtxxZTjbuvNMz .doneText2,#mermaid-svg-w6aDtxxZTjbuvNMz .doneText3{fill:#000 !important}#mermaid-svg-w6aDtxxZTjbuvNMz .crit0,#mermaid-svg-w6aDtxxZTjbuvNMz .crit1,#mermaid-svg-w6aDtxxZTjbuvNMz .crit2,#mermaid-svg-w6aDtxxZTjbuvNMz .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-w6aDtxxZTjbuvNMz .activeCrit0,#mermaid-svg-w6aDtxxZTjbuvNMz .activeCrit1,#mermaid-svg-w6aDtxxZTjbuvNMz .activeCrit2,#mermaid-svg-w6aDtxxZTjbuvNMz .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-w6aDtxxZTjbuvNMz .doneCrit0,#mermaid-svg-w6aDtxxZTjbuvNMz .doneCrit1,#mermaid-svg-w6aDtxxZTjbuvNMz .doneCrit2,#mermaid-svg-w6aDtxxZTjbuvNMz .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-w6aDtxxZTjbuvNMz .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-w6aDtxxZTjbuvNMz .milestoneText{font-style:italic}#mermaid-svg-w6aDtxxZTjbuvNMz .doneCritText0,#mermaid-svg-w6aDtxxZTjbuvNMz .doneCritText1,#mermaid-svg-w6aDtxxZTjbuvNMz .doneCritText2,#mermaid-svg-w6aDtxxZTjbuvNMz .doneCritText3{fill:#000 !important}#mermaid-svg-w6aDtxxZTjbuvNMz .activeCritText0,#mermaid-svg-w6aDtxxZTjbuvNMz .activeCritText1,#mermaid-svg-w6aDtxxZTjbuvNMz .activeCritText2,#mermaid-svg-w6aDtxxZTjbuvNMz .activeCritText3{fill:#000 !important}#mermaid-svg-w6aDtxxZTjbuvNMz .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-w6aDtxxZTjbuvNMz g.classGroup text .title{font-weight:bolder}#mermaid-svg-w6aDtxxZTjbuvNMz g.clickable{cursor:pointer}#mermaid-svg-w6aDtxxZTjbuvNMz g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-w6aDtxxZTjbuvNMz g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-w6aDtxxZTjbuvNMz .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-w6aDtxxZTjbuvNMz .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-w6aDtxxZTjbuvNMz .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-w6aDtxxZTjbuvNMz .dashed-line{stroke-dasharray:3}#mermaid-svg-w6aDtxxZTjbuvNMz #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w6aDtxxZTjbuvNMz #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w6aDtxxZTjbuvNMz #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-w6aDtxxZTjbuvNMz #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-w6aDtxxZTjbuvNMz #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w6aDtxxZTjbuvNMz #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w6aDtxxZTjbuvNMz #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w6aDtxxZTjbuvNMz #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w6aDtxxZTjbuvNMz .commit-id,#mermaid-svg-w6aDtxxZTjbuvNMz .commit-msg,#mermaid-svg-w6aDtxxZTjbuvNMz .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-w6aDtxxZTjbuvNMz g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-w6aDtxxZTjbuvNMz g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-w6aDtxxZTjbuvNMz g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-w6aDtxxZTjbuvNMz .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-w6aDtxxZTjbuvNMz .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-w6aDtxxZTjbuvNMz .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-w6aDtxxZTjbuvNMz .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-w6aDtxxZTjbuvNMz .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-w6aDtxxZTjbuvNMz .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-w6aDtxxZTjbuvNMz .edgeLabel text{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w6aDtxxZTjbuvNMz .node circle.state-start{fill:black;stroke:black}#mermaid-svg-w6aDtxxZTjbuvNMz .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-w6aDtxxZTjbuvNMz #statediagram-barbEnd{fill:#9370db}#mermaid-svg-w6aDtxxZTjbuvNMz .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-w6aDtxxZTjbuvNMz .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-w6aDtxxZTjbuvNMz .statediagram-state .divider{stroke:#9370db}#mermaid-svg-w6aDtxxZTjbuvNMz .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-w6aDtxxZTjbuvNMz .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-w6aDtxxZTjbuvNMz .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-w6aDtxxZTjbuvNMz .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-w6aDtxxZTjbuvNMz .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-w6aDtxxZTjbuvNMz .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-w6aDtxxZTjbuvNMz .note-edge{stroke-dasharray:5}#mermaid-svg-w6aDtxxZTjbuvNMz .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-w6aDtxxZTjbuvNMz .error-icon{fill:#522}#mermaid-svg-w6aDtxxZTjbuvNMz .error-text{fill:#522;stroke:#522}#mermaid-svg-w6aDtxxZTjbuvNMz .edge-thickness-normal{stroke-width:2px}#mermaid-svg-w6aDtxxZTjbuvNMz .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-w6aDtxxZTjbuvNMz .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-w6aDtxxZTjbuvNMz .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-w6aDtxxZTjbuvNMz .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-w6aDtxxZTjbuvNMz .marker{fill:#333}#mermaid-svg-w6aDtxxZTjbuvNMz .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}#mermaid-svg-w6aDtxxZTjbuvNMz {color: rgba(0, 0, 0, 0.75);font: ;}

布置于
布置于
布置于
布置于
布置于
创建一个窗体
窗体里添加容器
组件
边界布局
尺寸
坐标
是否可见
西

三、例子

1. 情况1

在窗体布置东、西、南、北、中布置按钮。

(1)源码A

/**所想:边界布局Border(边界)*/import java.awt.BorderLayout;// 边界布局
import java.awt.Container;// 容器import javax.swing.*;// 窗体class Demo extends JFrame{public Demo(){setBounds(40,30,320,180);// 窗体坐标、长宽setDefaultCloseOperation(EXIT_ON_CLOSE);// 点击×程序停止运行Container c=getContentPane();// 添加容器cc.setLayout(new BorderLayout());// 设置边界布局放于容器c中;Border(边界)// 创建按钮b_1,标签名诶“按钮-中”,后面b_2等以此类推JButton b_1=new JButton("按钮(中1)"),b_2=new JButton("按钮(东)"),b_3=new JButton("按钮(西)"),b_4=new JButton("按钮(南)"),b_5=new JButton("按钮(北)");c.add(b_1,BorderLayout.CENTER);// 将按钮b_1添加到窗体中部;center(中)c.add(b_2,BorderLayout.EAST);// 将按钮b_2添加到窗体东部;east(东)c.add(b_3,BorderLayout.WEST);// west(西)c.add(b_4,BorderLayout.SOUTH);// south(南)c.add(b_5,BorderLayout.NORTH);// north(北)setVisible(true);// 窗体是否可见}public static void main(String[] args){new Demo();}
}

(2)源码A运行效果

2. 情况2

前边代码A的中间部分代码为“中1”,现在在原有代码基础上添加一个中间按钮“中2”,则“中1”便会被“中2”替代。

(1)源码B

/**所想:边界布局Border(边界)*/import java.awt.BorderLayout;// 边界布局
import java.awt.Container;// 容器import javax.swing.*;// 窗体class Demo extends JFrame{public Demo(){setBounds(40,30,320,180);// 窗体坐标、长宽setDefaultCloseOperation(EXIT_ON_CLOSE);// 点击×程序停止运行Container c=getContentPane();// 添加容器cc.setLayout(new BorderLayout());// 设置边界布局放于容器c中;Border(边界)// 创建按钮b_1,标签名诶“按钮-中”,后面b_2等以此类推JButton b_1=new JButton("按钮(中1)"),b_2=new JButton("按钮(东)"),b_3=new JButton("按钮(西)"),b_4=new JButton("按钮(南)"),b_5=new JButton("按钮(北)");c.add(b_1,BorderLayout.CENTER);// 将按钮b_1添加到窗体中部;center(中)c.add(b_2,BorderLayout.EAST);// 将按钮b_2添加到窗体东部;east(东)c.add(b_3,BorderLayout.WEST);// west(西)c.add(b_4,BorderLayout.SOUTH);// south(南)c.add(b_5,BorderLayout.NORTH);// north(北)// 在原有位置比如“中”再添加一个按钮中2,则原来中1就会被中2覆盖显示c.add(new JButton("按钮(中2)"),BorderLayout.CENTER);setVisible(true);// 窗体是否可见}public static void main(String[] args){new Demo();}
}

(2)源码B运行效果

3. 情况3

前边源码A运行效果下的中间按钮为按钮“中1”,如果把关于中间的代码注释掉,运行效果的变化也只是取消中间部分的按钮,中间位置处于被未被使用状态。

(1)源码C

/**所想:边界布局Border(边界)*/import java.awt.BorderLayout;// 边界布局
import java.awt.Container;// 容器import javax.swing.*;// 窗体class Demo extends JFrame{public Demo(){setBounds(40,30,320,180);// 窗体坐标、长宽setDefaultCloseOperation(EXIT_ON_CLOSE);// 点击×程序停止运行Container c=getContentPane();// 添加容器cc.setLayout(new BorderLayout());// 设置边界布局放于容器c中;Border(边界)// 创建按钮b_1,标签名诶“按钮-中”,后面b_2等以此类推JButton //b_1=new JButton("按钮(中1)"),b_2=new JButton("按钮(东)"),b_3=new JButton("按钮(西)"),b_4=new JButton("按钮(南)"),b_5=new JButton("按钮(北)");//c.add(b_1,BorderLayout.CENTER);// 将按钮b_1添加到窗体中部;center(中)c.add(b_2,BorderLayout.EAST);// 将按钮b_2添加到窗体东部;east(东)c.add(b_3,BorderLayout.WEST);// west(西)c.add(b_4,BorderLayout.SOUTH);// south(南)c.add(b_5,BorderLayout.NORTH);// north(北)setVisible(true);// 窗体是否可见}public static void main(String[] args){new Demo();}
}

(2)源码C运行效果

四、定位日期

2021.4.20;22:16

java:布局方法(边界布局)相关推荐

  1. Java Swing面板布局之边界布局BorderLayout

    一.简介 边界布局管理器把容器的的布局分为五个位置:CENTER.EAST.WEST.NORTH.SOUTH.依次对应为:上北(NORTH).下南(SOUTH).左西(WEST).右东(EAST),中 ...

  2. Swing布局之边界布局(BorderLayout)

    边界布局在swing的布局中用的频率应该是最高的,像jpanel,jdialog都可以设置布局 使用方式: package com.fepc.commons.exports;import java.a ...

  3. CSS 布局 - grid - 二维布局方法 - 网格布局

    目录 一.grid 二维布局模块 二.基本概念 理解逻辑 - 容器 - 项目 理解行列 - 二维布局 理解单元格 网格线 三.容器属性 使用方法 CSS 重要属性配置 grid-template-co ...

  4. Java——BorderLayout(边界布局)

    在写java图形化界面时,遇到BorderLayout布局遇到一个小问题,折腾了半天,发现是没有好好理解BorderLayout的用法.下面来记录一下: 问题: 在布局时,很自然的从 北-->中 ...

  5. java常用布局管理器(流布局管理器、边界布局管理器、网格布局管理器)

    在Swing中,每个组件在容器中都有一个具体的位置大小.而在容器中摆放各种组件时很难判断其具体位置和大小,使用布局管理器比程序员直接在容器中控制Swing组件的位置和大小方便得多,可以更加有效地处理整 ...

  6. java:布局方法(网格布局)

    网格布局 一.简单说明 二.关键代码 三.流程图 四.例子说明 1. 有17个"按钮"排列 (1)源码A (2)运行效果 2. 有36个"按钮"排列 (1)源码 ...

  7. java边界布局东南西北_JAVA swing布局管理器实例解析

    组件在容器(比如Jframe)中的位置和大小是由布局管理器来决定的.所有的容器都会使用一个布局管理器,通过它来自动进行组件的布局管理. 种类 java共提供了五种布局管理器,只介绍三种是最常见的布局管 ...

  8. Java-Swing- BorderLayout() 边界布局

    Java-Swing- BorderLayout() 边界布局: package com.etc.layoutmanage;import javax.swing.*; import java.awt. ...

  9. Java窗体常用的布局

    常见的布局有 绝对布局,流式布局,边界布局和网格布局,具体的实现办法如下所示: 1:局对布局: package demo;import java.awt.Container; import java. ...

  10. 响应式布局方法的方法

    响应式布局方法 百分比布局 bootstrap栅格系统(antdesign 里面的珊格布局) Flex 伸缩盒布局 媒体查询

最新文章

  1. SAP PM 入门系列4 - 如何手工触发一个新的PM检验批?
  2. SAP SD微观研究之销售发票自动生成初探
  3. c语言计算器实现简单的四则运算.(加,减,乘,除)实验报告,C语言数据结构“简单计算器。”1、简单计算器。请按照四则运算加、减、乘、除、幂(^)和括号的优先关系和惯例,编写计算器程...
  4. 禁忌搜索算法求解带时间窗的车辆路径问题原理讲解
  5. os_mem.c(全)
  6. 3D Object Classification With Point Convolution —— 点云卷积网络
  7. 国家开放大学2021春1073法律文书答案
  8. C4D素材背景模板|广泛应用电商场景和展览的运用
  9. python中的缩进是长度统一吗_python缩进长度是否统一
  10. Java---类反射(1)---类反射入门和基础
  11. 哈工大网络安全实验五报告
  12. winqsb替代软件linux,winqsb软件64位-运筹学软件winqsb下载 v3.0免费版 附使用教程-下载啦...
  13. Json格式以及常见的Json解析器
  14. ibm刀片服务器虚拟化,刀片服务器内置虚拟化 IBM升级服务器
  15. baidupcsgo安卓_GitHub - orenbek2019/BaiduPCS-Go: 百度网盘客户端 - Go语言编写
  16. 浏览器主页被篡改为hao123、360和2345解决办法
  17. P3320 [SDOI2015]寻宝游戏
  18. Oracle账号 Oracle官网登录下载资源账号密码共享
  19. 临时执法卡点的设置原理与选址分析
  20. 将sublime右下角永远改为HTML格式

热门文章

  1. 松翰单片机定时器c语言,松翰T0 定时器中断
  2. mp3中不可缺少的音乐
  3. 计算机无法连接移动硬盘,移动硬盘无法访问解决大全
  4. Java--------面向对象
  5. 智能防盗报警系统前端报警设备的选择
  6. 朱晔的互联网架构实践心得S2E7:漫谈平台架构的工作(基础架构、基础服务、基础平台、基础中间件等等)
  7. 亮宁机器人套件_十大可编程机器人教育套件
  8. ZA303学习笔记十部署负载均衡器和网络安全
  9. matlab fft 作图,Matlab绘图示例
  10. 诗画丽水 文化传承 萌娃上演宋韵国风非遗主题秀