Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Tired of Hibernate? Try JDBI in your code JDBI Quick sample ICategoryDAO.java : create a data access interface (implement is not required) package com.prhythm.erotic.task.data.... Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement...
Stats
CookSwing
CookSwing is a library which builds Java Swing GUI from XML documents. It is under continuously active development, since I make a living by doing Swing GUI :) Unlike many other XUL toolkits, Swing is complete in its capability dealing with Swing and beyond. It is mature and stable. If you like this library, please help spreading the word.

CookSwing: XML to Java Swing GUI

MyPanel.xml
<?xml version="1.0" encoding="UTF-8"?>
<panel>
    <flowlayout>
        <label id="lbHello" text="Hello World Again!" horizontalalignment="CENTER" foreground="#ff0000" font="Serif,bold italic,20" />
        <button text="test" actionlistener="btnTest_Click" />
    </flowlayout>
</panel>
MyPanel.java
package cs;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;

import cookxml.cookswing.CookSwing;

public class MyPanel extends JPanel {

    public String msg;

    // action variant for CookSwing
    public Action btnTest_Click = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {

            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), MyPanel.this.toString());
        }
    };

    // constructor with arguments
    public MyPanel(String msg) {
        this.msg = msg;
    }

    // customized method, this method can't be assign to rendered object
    public void randomCode() {
        // do something
        JOptionPane.showConfirmDialog(JOptionPane.getRootFrame(), "Test code");
    }

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("CookSwing basic usage");

        MyPanel panel = new MyPanel("My name is bruce.");
        CookSwing cs = new CookSwing(panel);
        Container container = cs.render("cs/MyPanel.xml");

        // pane & container are two different instance
        System.out.println(panel);
        System.out.println(container);
        // get object by id
        System.out.println(cs.getId("lbHello").object);

        frame.setContentPane(container);
        frame.pack();

        Dimension sc = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((sc.width - frame.getWidth()) / 2, (sc.height - frame.getHeight()) / 2);
        frame.setVisible(true);
    }

}

It is a pity that CookSwing, not like SwiXml, can't render object itself, but create a new instance for using. In this condition, I msut create a component by assign a instance (variant) and a xml document, instead of by using new . And I can't specify a public method for redered object to invoke some process.