本文介绍了将jtoolbar从一个jpanel转移到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的第一个问题,请多多包涵.假设我有2个JPanel和1个JToolBar.我要做的是将工具栏从一个面板拖到另一个面板,放开鼠标后,工具栏应停留在第二个面板上.
This is my first question, so bear with me. Let's say that I have 2 JPanel and 1 JToolBar. What I want to do is drag the toolbar from one panel to another and, after mouse release, the toolbar should stick to the second.
推荐答案BasicToolbarUI具有floatAt方法.如您从源代码中看到的(在下面),工具栏使用了docing源,它是工具栏的父容器.您可以尝试覆盖该方法并替换源.
BasicToolbarUI has floatAt method. As you can see from source (below) toolbar uses docing source which is toolbar's parent container. You can try to override the method and replace the source.
protected void floatAt(Point position, Point origin) { if(toolBar.isFloatable() == true) { try { Point offset = dragWindow.getOffset(); if (offset == null) { offset = position; dragWindow.setOffset(offset); } Point global = new Point(origin.x+ position.x, origin.y+position.y); setFloatingLocation(global.x-offset.x, global.y-offset.y); if (dockingSource != null) { Point dockingPosition = dockingSource.getLocationOnScreen(); Point comparisonPoint = new Point(global.x-dockingPosition.x, global.y-dockingPosition.y); if (canDock(dockingSource, comparisonPoint)) { setFloating(false, comparisonPoint); } else { setFloating(true, null); } } else { setFloating(true, null); }更多推荐
将jtoolbar从一个jpanel转移到另一个
发布评论