将jtoolbar从一个jpanel转移到另一个

编程入门 行业动态 更新时间:2024-10-06 22:30:58
本文介绍了将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转移到另一个

本文发布于:2023-07-09 10:09:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085540.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转移到   jtoolbar   jpanel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!