简体   繁体   English

Java 垂直对齐按钮

[英]Java Vertically Align Buttons

So here's my project:所以这是我的项目: 项目

So what I want to do is vertically align my color buttons while still having a horizontal-south border layout.所以我想要做的是垂直对齐我的颜色按钮,同时仍然具有水平向南的边框布局。 I want to align two colors vertically.我想垂直对齐两种颜色。 One top color then one bottom color.一种顶部颜色然后一种底部颜色。 Then the next two colors will do the same thing next to it.然后接下来的两种颜色将在它旁边做同样的事情。

I want to align two colors vertically.我想垂直对齐两种颜色。 One top color then one bottom color.一种顶部颜色然后一种底部颜色。 Then the next two colors will do the same thing next to it.然后接下来的两种颜色将在它旁边做同样的事情。

Create a JPanel using a GridLayout, then add the buttons to the panel.使用 GridLayout 创建一个 JPanel,然后将按钮添加到面板。 Finallly add that panel to your panel that you add to the south:最后将该面板添加到您添加到南部的面板中:

JPanel buttons = new JPanel( new GridLayout(2, 0) );
buttons.add(redButton);
buttons.add(greenButton);
buttons.add(blueButton);
southPanel.add( buttons );
southPanel.add( clearButton );

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

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