JPanel中的JButton方向 [英] JButton orientation within a JPanel

查看:213
本文介绍了JPanel中的JButton方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为图像编辑器设计一个GUI,其中有多个按钮,这些按钮可以对所选图像应用不同的效果.目前,我在窗口的顶部中央有显示"按钮,在窗口的底部中央有加载"按钮,并且我希望效果按钮堆叠在窗口的左侧.这是我的GUI的图像,红色ButtonPanel JPanel,绿色FileChooser JPanel,蓝色ImageDisplay JPanel:

I am designing a GUI for an image editor in which I have multiple buttons which apply different effects to the selected image. Currently I have the Display button in the top center of the window, the Load button in the bottom center of the window, and I want the effect buttons stacked on the left side of the window. Here is the image of my GUI, with the ButtonPanel JPanel in red, the FileChooser JPanel in green, and the ImageDisplay JPanel in blue:

如您所见,ButtonPanel中的按钮是水平堆叠而不是垂直堆叠.我希望它们垂直堆叠.谢谢您的帮助.

As you can see, the buttons in the ButtonPanel are stacking horizontally instead of vertically. I would like them to stack vertically. Thank you for the help.

推荐答案

ButtonPanel中的按钮是水平堆叠,而不是垂直堆叠.我希望它们垂直堆叠.

the buttons in the ButtonPanel are stacking horizontally instead of vertically. I would like them to stack vertically.

JPanel的默认布局是FlowLayout,它将水平显示所有组件.

The default layout for a JPanel is a FlowLayout which displays all components horizontally.

使用其他布局管理器.也许是GridLayout.如果正确设置了构造函数参数,则使用GridLayout可以垂直显示组件.

Use a different Layout Manager. Maybe a GridLayout. With a GridLayout you can display components vertically if you set the constructor parameters properly.

布局管理器上,从Swing教程中阅读本节.有关更多信息和工作示例.

Read the section from the Swing tutorial on Layout Managers for more information and working examples.

这篇关于JPanel中的JButton方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆