`

SwingC API 演示DEMO,不断更新

 
阅读更多

原文 本帖不再更新,以后发布在这儿

 

1、运行一个带换肤的窗体

 

SwingUtil.runApp(new SkinableWindow());

  效果:


 

 

2、Form的使用

 

表单代码:

 

import java.awt.Color;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;

import org.sky.swing.app.Form;

import craky.componentc.JCLabel;
import craky.componentc.JCLimitedPassword;
import craky.componentc.JCTextField;

public class TestForm extends Form {

	private static final long serialVersionUID = -7663014363916344347L;

	@Override
	protected List<Component> initFormItems() {
		ArrayList<Component> formItems = new ArrayList<Component>();

		JCLabel lbAddAdmin = new JCLabel("首次使用,请先注册超级管理员账号。");
		lbAddAdmin.setForeground(new Color(255, 40, 110));
		lbAddAdmin.setPreferredSize(getItemPreferredSize());
		formItems.add(lbAddAdmin);

		formItems.add(new FormItem("用户名:", new JCTextField()));
		formItems.add(new FormItem("旧密码:", new JCLimitedPassword()));
		formItems.add(new FormItem("新密码:", new JCLimitedPassword()));
		formItems.add(new FormItem("密码确认:", new JCLimitedPassword()));

		return formItems;
	}
}

 测试:

 

 

import java.awt.Dimension;

import org.sky.swing.app.SkinableWindow;
import org.sky.swing.app.SwingUtil;

public class TestApp extends SkinableWindow {

	private static final long serialVersionUID = -624742720343787933L;

	@Override
	protected void initUI() {
		super.initUI();
		
		getContentPane().add(new TestForm());

		setSize(new Dimension(400, 200));
		setTitle("测试表单");
	}

	public static void main(final String... args) {

		SwingUtil.runApp(new TestApp());
	}
}

 

 效果:


 

 

3、Tree的使用

 

示例:

import java.util.Enumeration;
import java.awt.Dimension;
import javax.swing.tree.DefaultMutableTreeNode;

import org.sky.swing.app.SkinableWindow;
import org.sky.swing.app.SwingUtil;

import craky.componentc.JCTree;

public class TestTreeApp extends SkinableWindow {

	private static final long serialVersionUID = -624742720343787933L;

	@Override
	protected void initUI() {
		super.initUI();

		JCTree tree = new JCTree(getTree());
		tree.setEditable(true);
		
		getContentPane().add(tree);

		setSize(new Dimension(200, 400));
		setTitle("测试Tree");
	}

	private DefaultMutableTreeNode getTree() {
		DefaultMutableTreeNode root = new DefaultMutableTreeNode("朋友列表");

		String[] group = new String[]{"我的好友", "同学", "陌生人", "黑名单"};
		for (String string : group) {
			root.add(new DefaultMutableTreeNode(string));
		}

		String[] person = new String[]{"张", "王", "李", "赵", "孙"};
		Enumeration<?> children = root.children();
		while (children.hasMoreElements()) {
			DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
			
			for (String string : person) {
				node.add(new DefaultMutableTreeNode(node.getUserObject() + string));
			}
		}

		return root;
	}

	public static void main(final String... args) {

		SwingUtil.runApp(new TestTreeApp());
	}
}

 效果:


  • 大小: 56.5 KB
  • 大小: 20.2 KB
  • 大小: 17 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics