/* * $Id: StatusBarDemo.java,v 1.5 2005/10/31 13:48:14 zfq Exp $ * * Copyright (C) 2001-2003 Extreme Component, Inc. All rights reserved. * Use is subject to license terms. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import com.zfqjava.swing.JStatusBar; import com.zfqjava.swing.JBean; import com.zfqjava.swing.JCommonPane; /** * JStatusBar Demo * * @author $Author: zfq $ * @version $Revision: 1.5 $ $Date: 2005/10/31 13:48:14 $ */ public class StatusBarDemo extends JPanel { private JStatusBar statusBar; public StatusBarDemo() { setLayout(new BorderLayout()); add(createCenterPanel(), BorderLayout.CENTER); add(createPropertyPanel(), BorderLayout.EAST); } private JPanel createCenterPanel() { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); statusBar = createStatusBar(); panel.add(statusBar, BorderLayout.SOUTH); return panel; } private JProgressBar progressBar; private JStatusBar createStatusBar() { JStatusBar statusBar = new JStatusBar(); statusBar.setText("hello"); progressBar = statusBar.getProgressBar(); return statusBar; } private JPanel createPropertyPanel() { JPanel panel = new JPanel(); Border titledBorder = new TitledBorder("Change Property"); Border emptyBorder = new EmptyBorder(12, 12, 12, 12); panel.setBorder(BorderFactory.createCompoundBorder(titledBorder, emptyBorder)); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); panel.setLayout(gridbag); c.weightx = 0.5; c.weighty = 0.5; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(0, 0, 5, 0); JLabel label = new JLabel("Client Border: "); addPanel(panel, c, label); Object[] headStyles = { "Lowered", "Flat" }; final JComboBox headStyleCB = new JComboBox(headStyles); headStyleCB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object item = headStyleCB.getSelectedItem(); statusBar.putClientProperty("JStatusBar.clientBorder", item); } }); label.setLabelFor(headStyleCB); c.gridwidth = GridBagConstraints.REMAINDER; addPanel(panel, c, headStyleCB); c.gridwidth = GridBagConstraints.RELATIVE; JButton b = new JButton("Start progress"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // init progressBar.setVisible(true); progressBar.setValue(0); value = 0; startTimer(); } }); addPanel(panel, c, b); return panel; } private int value; private void startTimer() { Timer timer = new Timer(100, new ActionListener() { public void actionPerformed(ActionEvent e) { value ++; if(value >= progressBar.getMaximum()) { progressBar.setVisible(false); } else { progressBar.setValue(value); } } }); timer.start(); } private static void addPanel(Container container, GridBagConstraints c, Component component) { GridBagLayout gridbag = (GridBagLayout)container.getLayout(); gridbag.setConstraints(component, c); container.add(component); } public static void main(String[] args) { DemoPanel demoPanel = new DemoPanel(); demoPanel.addDemo(new StatusBarDemo()); demoPanel.setTitle("JStatusBar Demo"); demoPanel.setDefaultCloseOperation(JBean.EXIT_ON_CLOSE); demoPanel.showFrame(); } }