http://www.swixml.org/index.html
Building GUIs with SwiXml
Version 1.5, supported Layout :
FlowLayout
BorderLayout
GridLayout
GridBagLayout
BoxLayout
CardLayout
XPanel.xml
<?xml version="1.0" encoding="UTF-8"?> <panel Layout="flowlayout"> <label text="條碼" /> <textfield id="txtBarCode" columns="30" /> <button id="btnEnter" text="輸入" action="btnEnter_click" /> </panel>XPanel.java
package swixml.sample; import java.awt.Color; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.util.UUID; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import org.swixml.SwingEngine; public class XPanel extends JPanel { public Action btnEnter_click = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { System.out.println(txtBarCode.getText()); } }; JTextField txtBarCode; JButton btnEnter; public XPanel() throws Exception { new SwingEngine(this).insert("swixml/sample/XPanel.xml", this); // other setting btnEnter.setForeground(Color.red); } // customized method public void randomCode() { txtBarCode.setText(UUID.randomUUID().toString()); } /** * @param args */ public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { // TODO Auto-generated catch block e.printStackTrace(); } MFrame frame = new MFrame(); // invoke method ((XPanel) frame.getContentPane()).randomCode(); } } class MFrame extends JFrame { public MFrame() { try { setContentPane(new XPanel()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } setTitle("SwiXML Panel Sample"); pack(); Dimension sc = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((sc.width - getWidth()) / 2, (sc.height - getHeight()) / 2); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } }