Example usage for javax.swing DefaultButtonModel DefaultButtonModel

List of usage examples for javax.swing DefaultButtonModel DefaultButtonModel

Introduction

In this page you can find the example usage for javax.swing DefaultButtonModel DefaultButtonModel.

Prototype

public DefaultButtonModel() 

Source Link

Document

Constructs a DefaultButtonModel.

Usage

From source file:Main.java

public static void main(String[] args) {
    final JButton ok = new JButton("ok");
    JCheckBox cb = new JCheckBox("Enabled", true);
    cb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ok.isEnabled())
                ok.setEnabled(false);// w  w w  . ja  v a2  s. c o  m
            else
                ok.setEnabled(true);
        }
    });

    ButtonModel model = new DefaultButtonModel() {
        public void setEnabled(boolean b) {
            if (b)
                System.out.println("Pressed: true");
            else
                System.out.println("Pressed: false");

            super.setEnabled(b);
        }

        public void setArmed(boolean b) {
            if (b)
                System.out.println("Armed: true");
            else
                System.out.println("Armed: false");

            super.setArmed(b);
        }

        public void setPressed(boolean b) {
            if (b)
                System.out.println("Pressed: true");
            else
                System.out.println("Pressed: false");

            super.setPressed(b);
        }

    };

    ok.setModel(model);

    JFrame f = new JFrame();
    f.setLayout(new FlowLayout());
    f.add(ok);
    f.add(cb);

    f.setSize(350, 250);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Panels.FinanzPanel.java

public FinanzPanel(DetailContainer dc) {
    this.dc = dc;
    initComponents();/*w w w  .  ja  v  a 2s.  co m*/
    dataset = new DefaultPieDataset();
    ;
    //        //dataset.addSeries("xy", A);
    //        dataset.setValue("One", new Double(43.2));
    //        dataset.setValue("Two", new Double(10.0));
    renderer = new XYSplineRenderer();
    ////        xax = new NumberAxis("x");
    ////        yax = new NumberAxis("y");
    plot = new PiePlot(dataset);
    //        //plot = new XYPlot(dataset,xax,yax, renderer);
    chart1 = new JFreeChart(plot);
    chartPanel1 = new ChartPanel(chart1);
    chartPanel1.setMouseWheelEnabled(true);
    //        this.jPanel1.setLayout(new java.awt.BorderLayout());
    this.jPanel1.add(chartPanel1);
    this.jButton1.setModel(new DefaultButtonModel());
    //        this.add(new JButton("back"), BorderLayout.SOUTH );
    this.validate();
}

From source file:ome.formats.importer.gui.FileQueueTable.java

private void updateGroupBtn(String groupName, int groupLevel) {
    groupBtn.setText(groupName);/*from   ww w  .j  a va  2 s . co m*/
    IconManager icons = IconManager.getInstance();
    Icon groupIcon = null;

    if (groupLevel == ImportEvent.GROUP_PUBLIC)
        groupIcon = icons.getIcon(IconManager.PUBLIC_GROUP);
    if (groupLevel == ImportEvent.GROUP_COLLAB_READ)
        groupIcon = icons.getIcon(IconManager.READ_GROUP);
    if (groupLevel == ImportEvent.GROUP_COLLAB_READ_LINK)
        groupIcon = icons.getIcon(IconManager.READ_LINK_GROUP);
    if (groupLevel == ImportEvent.GROUP_PRIVATE)
        groupIcon = icons.getIcon(IconManager.PRIVATE_GROUP);

    groupBtn.setIcon(groupIcon);
    groupBtn.setPreferredSize(new Dimension(160, 20));

    // TODO: For now disable the button
    DefaultButtonModel model = new DefaultButtonModel() {
        private static final long serialVersionUID = 1L;

        public void setArmed(boolean armed) {
        }

        public void setPressed(boolean pressed) {
        }

        public void setRollover(boolean rollover) {
        }
    };
    groupBtn.setModel(model);
    groupBtn.invalidate();
    groupBtn.setFocusable(false);
}