| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 805 人关注过本帖
标题:[小娱乐] 一个能拖动组件、改变组件大小的容器
只看楼主 加入收藏
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
 问题点数:0 回复次数:5 
[小娱乐] 一个能拖动组件、改变组件大小的容器
/*
* 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.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">
private void initComponents() {

}// </editor-fold>


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


/**
* 将组件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;
}

}

搜索更多相关主题的帖子: 拖动组件 组件大小 容器 import awt 
2007-03-20 01:48
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
回复:(神vLinux飘飘)[小娱乐] 一个能拖动组件、改...
一个DEMO
/*
* DragpullDemo.java
*
* Created on 2007年3月20日, 上午1:50
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package examples.javax.swing;

import javax.swing.JDragpullPane;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;

/**
*
* @author vlinux
*/
public class DragpullDemo extends JFrame {

/**
* Creates a new instance of DragpullDemo
*/
public DragpullDemo() {
JDragpullPane pane = new JDragpullPane();
this.getRootPane().setContentPane( pane );

JTextArea textArea = new JTextArea(20,50);
textArea.setBounds(10,20,30,40);

JTable table = new JTable();
table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
table.setBounds(30,30,70,150);

pane.add( textArea );
pane.add( table );


setBounds(100,200,300,400);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
}


public static void main(String... args) {
new DragpullDemo();
}

}


淘宝杜琨
2007-03-20 02:05
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 

可惜不是你,陪我到最后
2007-03-20 09:52
ILoveMK
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:487
专家分:0
注 册:2007-2-12
收藏
得分:0 
无聊,还是帮你顶一下吧~~

天下归心
2007-03-20 21:04
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
本来就不指望你明白~~哎~~~~

淘宝杜琨
2007-03-20 21:16
ILoveMK
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:487
专家分:0
注 册:2007-2-12
收藏
得分:0 
晕,怎么又做起斑竹来啦,看来大家还是冥顽不灵啊,看来又要发贴了~~

天下归心
2007-03-20 21:33
快速回复:[小娱乐] 一个能拖动组件、改变组件大小的容器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014810 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved