java拖动组件,[小娱乐] 一个能拖动组件、改变组件大小的容器

介绍了一种自定义Swing容器JDragpullPane,该容器支持子组件的拖动和大小调整功能。通过实现特定的方法,使得加入的组件可以根据用户操作改变位置和尺寸。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[小娱乐] 一个能拖动组件、改变组件大小的容器

/*

* JDragpullPane.java

*

* Created on 2007年3月20日, 上午12:31

*/

package javax.swing;

import java.awt.Color;

import java.awt.Component;

import java.awt.Rectangle;

import javax.swing.plaf.metal.MetalInternalFrameUI;

/**

* 一个能拖动组件、改变组件大小的容器

* @author vlinux

*/

public class JDragpullPane extends javax.swing.JDesktopPane {

/** Creates new form BeanForm */

public JDragpullPane() {

initComponents();

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

//

private void initComponents() {

}//

// 变量声明 - 不进行修改

// 变量声明结束

/**

* 将组件c添加到容器中

* 等效于 add( c, JDesktopPane.DEFAULT_LAYER, true )

*/

public Component add( Component c ) {

add( c, javax.swing.JDesktopPane.DEFAULT_LAYER );

return c;

}

/**

* 将组件C添加到容器中

* 等效于 add( c, o, true );

*/

public void add( Component c, Object o ) {

add( c, o, true );

}

/**

* 将组件C添加到容器中

* 其中 dragable 标明了该组件足否允许被拖动

* 等效于 add( c, o, dragable );

*/

public void add( Component c, Object o, boolean dragable ) {

Rectangle rect = c.getBounds();

ComponentPane comp = ComponentPane.instance( rect, dragable );

comp.add(c);

super.add( comp, o );

}

}

class ComponentPane extends javax.swing.JInternalFrame {

public ComponentPane( Rectangle rect ) {

super();

setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new Color(255, 102, 0)));

setBounds( rect );

setResizable(true);

setVisible( true );

}

public static ComponentPane instance( Rectangle rect, boolean dragable ) {

ComponentPane cp = new ComponentPane( rect );

MetalInternalFrameUI ui = (MetalInternalFrameUI) cp.getUI();

if( dragable ) {

ui.setPalette(true);

} else {

ui.setNorthPane(null);

}

return cp;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值