本文介绍了我将如何为这样的Gui设置布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我如何设置一个layoutmanager来创建这样的GUI? https://docs.google.com/drawings/d/1te1IpBLzcFnV8KXq4-RMQnRMQviyuaW7vUN0s7jODlA/edit?usp=sharing [ ^ ] i可以设置全部actionevents和使按钮做东西等但我不知道如何使用layoutmanager正确定位面板和按钮。How would i set up a layoutmanager to create a GUI like this?https://docs.google.com/drawings/d/1te1IpBLzcFnV8KXq4-RMQnRMQviyuaW7vUN0s7jODlA/edit?usp=sharing[^]i can set up all the actionevents and make the buttons do stuff etc but i just dont know how to position the panels and buttons correctly using a layoutmanager.推荐答案import java.awt.Color;import java.awt.GridLayout;import javax.swing.JFrame;import javax.swing.JPanel;public class MyFrame extends JFrame {private JPanel panelLeft = new JPanel();private JPanel panelRight = new JPanel();private JPanel panelLeftTop = new JPanel();private JPanel panelLeftBottom = new JPanel();public MyFrame(){this.ignition();}private void ignition() {this.setSize(800,600);this.setLayout(new GridLayout(1, 2));panelLeft.setBackground(Color.RED);panelRight.setBackground(Color.GREEN);panelLeftTop.setBackground(Color.YELLOW);panelLeftBottom.setBackground(Color.BLUE);// inside left panelpanelLeftTop.setSize(400,300);panelLeftBottom.setSize(400,300);//giving left panel a layout and adding componentspanelLeft.setLayout(new GridLayout(2,1));panelLeft.add(panelLeftTop);panelLeft.add(panelLeftBottom);//adding the panels to the JFramethis.add(panelLeft);this.add(panelRight);}public static void main(String[] args) {new MyFrame().setVisible(true);}} 这篇关于我将如何为这样的Gui设置布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 18:49