简体   繁体   English

如何将 JPanel 从应用程序的东侧移动到西侧?

[英]How do I move a JPanel from the East side of an application to the West?

There is an open source client for a game I play but some of the UI elements are not my favorite so I've looking through the code trying to make changes.我玩的游戏有一个开源客户端,但一些 UI 元素不是我最喜欢的,所以我一直在查看代码,试图做出改变。 I've been able to resolve most issues I've run into but I'm stumped with this one.我已经能够解决我遇到的大多数问题,但我被这个问题难住了。 My goal is to change the location of the sidebar from the right side of the game window to the left.我的目标是将侧边栏的位置从游戏 window 的右侧更改为左侧。

Here is an image for reference:这是一张图片供参考:

The red panel on the right is the current configuration and the green panel on the left is where I would like it moved to.右侧的红色面板是当前配置,左侧的绿色面板是我希望它移动到的位置。

After some digging I found code that controls this panel's layout:经过一番挖掘,我找到了控制此面板布局的代码:

        container = new JPanel();
        container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
        container.add(new ClientPanel(client));

I've tried changing the end of the second line "BoxLayout.X_AXIS" to Y_AXIS, LINE_AXIS, and PAGE_AXIS but none of these had the desired outcome.我尝试将第二行“BoxLayout.X_AXIS”的结尾更改为 Y_AXIS、LINE_AXIS 和 PAGE_AXIS,但这些都没有达到预期的结果。

My main question is this.我的主要问题是这个。 Is there a way to change the middle line to keep the X Axis alignment but flip it to the West side of the screen?有没有办法改变中线以保持 X 轴 alignment 但将其翻转到屏幕的西侧?

I'm sure there is something obvious I'm missing but I haven't found a solution after multiple hours of research.我确定我缺少一些明显的东西,但经过多个小时的研究后我还没有找到解决方案。 I can provide more code if needed and I'll try to answer any questions to clarify what I'm asking if needed.如果需要,我可以提供更多代码,如果需要,我会尝试回答任何问题以澄清我在问什么。

Using Container.add(Component) adds the component at the end.使用Container.add(Component)在末尾添加组件。 If you wish to add it at any other position than the end, use Container.add(Component, int) , where the integer is the (zero-indexed) index you wish to add the component at.如果您希望将其添加到除末尾之外的任何其他 position 处,请使用Container.add(Component, int) ,其中 integer 是您希望添加组件的(零索引)索引。

Adding all components at the beginning instead of the end effectively reverses their order, which should result in your requested behaviour.在开头而不是结尾添加所有组件会有效地颠倒它们的顺序,这应该会导致您请求的行为。

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

相关问题 如何阻止BorderLayout的中心向东和向西移动? - How do I stop center of BorderLayout from taking up east and west? 如何将圆圈移动到“ WEST”边框布局框? - How do I move the circle to the “WEST” border layout frame? Java - 如何防止BorderLayout EAST拥抱屏幕的一侧? - Java - How do I prevent BorderLayout EAST from hugging the side of the screen? 如何在JPanel中移动图像 - How do I move the image in JPanel 如何获得BorderLayout的西方和东方? - How to get the west and east of a BorderLayout attached? 如何将JButton移动到JPanel的右侧? - How can I move my JButton to the right side of my JPanel? 在 java 的 GUI 中,除了 .north、.south、.east、.west、.center 之外,我还能使用什么? - What can I use aside from .north, .south, .east, .west, .center in a GUI in java? 如何在Frame中并排添加JPanel / JSplitPane组件? - How do I add JPanel/JSplitPane components side by side in a Frame? 如何将Enum与其相反的值相关联,如在主要方向(南北,东西等)? - How can I associate an Enum with its opposite value, as in cardinal directions (North - South, East - West, etc)? 如何从扩展线程的类开始在JPanel中创建动画(从一个点移动一个圆圈到另一个点)? - How do I start an animation (move a circle from one point to another) in a JPanel from a class that extends thread?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM