[英]Java Swing, how to make a JPanel resizable with mouse?
I have been developing an user interface with Java Swing, and I have met a problem in JPanel resizing. 我一直在用Java Swing开发用户界面,我遇到了JPanel大小调整的问题。
This is my problem: I would like to let a JPanel be resizable by the user, when the user points its mouse over the JPanel border line (as described in the following figure). 这是我的问题:当用户将鼠标指向JPanel边界线时,我想让用户调整JPanel(如下图所示)。 Now, if I move my mouse over that line, nothing happens. 现在,如果我将鼠标移到该线上,则没有任何反应。 I would like that I could change its size with my mouse. 我想我可以用鼠标改变它的大小。
Here's my code portion: 这是我的代码部分:
JTabbedPane _tabbedPane = new JTabbedPane();
JPanel gridAndCommandPaneValidation = new JPanel();
gridAndCommandPaneValidation.setLayout(new BorderLayout());
ValidationTableModel vtm = new ValidationTableModel(new LinkedList<DatabaseAnalysisValues>());
tableValidation = new JTable(vtm);
JScrollPane scrollpaneVal = new JScrollPane(tableValidation);
tableValidation.setAutoscrolls(true);
gridAndCommandPaneValidation.add(scrollpaneVal, BorderLayout.WEST);
gridAndCommandPaneValidation.add(getKBestValidationCommandsPanel(), BorderLayout.EAST);
_tabbedPane.add("Validation", gridAndCommandPaneValidation);
Is there anyone that can help me? 有没有人可以帮助我?
Many thanks! 非常感谢!
Take a look at JSplitPane
and the corresponding Java Tutorial . 看一下JSplitPane
和相应的Java Tutorial 。 This component can do exactly what you want and it behaves very well. 该组件可以完全按照您的要求执行,并且表现非常好。 Try the first example in the tutorial, you'll see. 试试教程中的第一个例子,你会看到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.