在一个JFrame中使用两个JPanel [英] Using two JPanels in one JFrame

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

问题描述

我正在尝试创建一个程序,允许用户单击按钮将某些内容放在 JPanel 中,并允许他们移动此项目。我已经找到了一个很好的布局来使用移动组件(参见摆动布局经理。


I'm attempting to create a program that allows the user to click a button to place something in the JPanel and allowing them to move this item around. I have already found a good layout to use to allow the moving components (see this link). However, I'm just curious the best way to create a layout like this? My hope is to have something like this:

How can I accomplish this? Would I want to use two JPanel's or something else?

解决方案

The main panel (or the window content pane) would have to have a BorderLayout as the layout manager.

Then, the buttons panel would be added to BorderLayout.WEST and the drag panel to BorderLayout.CENTER.

There is a Visual Guide to swing layout managers.

这篇关于在一个JFrame中使用两个JPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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