Example usage for javax.swing JButton getWidth

List of usage examples for javax.swing JButton getWidth

Introduction

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

Prototype

@BeanProperty(bound = false)
public int getWidth() 

Source Link

Document

Returns the current width of this component.

Usage

From source file:de.kletterfreak98.xmass.ui.BMIChart.java

public BMIChart(String title, TimeSeries values) {
    super(title);
    setIconImage(//from   w w  w .  j  a va 2  s  .  c  o  m
            new ImageIcon(getClass().getClassLoader().getResource("de/kletterfreak98/xmass/resources/fav.png"))
                    .getImage());

    // create a title...
    final String chartTitle = strings.getString("bmicourse");
    final XYDataset dataset = new TimeSeriesCollection(values);

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, strings.getString("date"),
            strings.getString("bmi"), dataset, false, true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setDataset(1, new TimeSeriesCollection(values));
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setShapesFilled(true);
    }

    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.black);
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    plot.setRenderer(1, renderer2);

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    SimpleDateFormat sdf;
    if (Main.settings.getLang().equals(Locale.GERMANY)) {
        sdf = new SimpleDateFormat("dd.MM.yyyy");
    } else {
        sdf = new SimpleDateFormat("MM/dd/yyyy");
    }
    axis.setDateFormatOverride(sdf);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    JPanel panel = new JPanel();
    JButton close = new JButton(strings.getString("close"));
    close.setPreferredSize(new Dimension(close.getWidth(), 30));
    close.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel, BorderLayout.CENTER);
    panel.add(close, BorderLayout.SOUTH);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(panel);
    setUndecorated(true);
}

From source file:de.kletterfreak98.xmass.ui.WeightChart.java

public WeightChart(String title, TimeSeries values) {
    super(title);

    setIconImage(/*  w w  w .jav  a 2  s.  co m*/
            new ImageIcon(getClass().getClassLoader().getResource("de/kletterfreak98/xmass/resources/fav.png"))
                    .getImage());

    final String chartTitle = strings.getString("weightcourse");
    final XYDataset dataset = new TimeSeriesCollection(values);

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, strings.getString("date"),
            strings.getString("weightinkg"), dataset, false, true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setDataset(1, new TimeSeriesCollection(values));
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setShapesFilled(true);
    }

    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.black);
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    plot.setRenderer(1, renderer2);

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    SimpleDateFormat sdf;
    if (Main.settings.getLang().equals(Locale.GERMANY)) {
        sdf = new SimpleDateFormat("dd.MM.yyyy");
        axis.setDateFormatOverride(sdf);
    } else {
        sdf = new SimpleDateFormat("MM/dd/yyyy");
        axis.setDateFormatOverride(sdf);
    }

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    JPanel panel = new JPanel();
    JButton close = new JButton(strings.getString("close"));
    close.setPreferredSize(new Dimension(close.getWidth(), 30));
    close.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel, BorderLayout.CENTER);
    panel.add(close, BorderLayout.SOUTH);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(panel);
    setUndecorated(true);
}

From source file:es.emergya.ui.plugins.AdminPanel.java

/**
 * /*from  www.  j a v  a  2  s .c om*/
 * @param columnNames
 *            nombres de las columnas de la tabla
 * @param filterOptions
 *            lista de opciones de un combobox. Si esta vacio entonces es un
 *            textfield
 * @param noFiltrarAction
 * @param filtrarAction
 */
public void generateTable(String[] columnNames, Object[][] filterOptions,
        AdminPanel.NoFiltrarAction noFiltrarAction, AdminPanel.FiltrarAction filtrarAction) {

    if (columnNames == null) {
        columnNames = new String[] {};
    }
    if (filterOptions == null) {
        filterOptions = new Object[][] {};
    }

    String filterString = "[";
    for (Object[] o : filterOptions) {
        filterString += Arrays.toString(o) + " ";
    }
    filterString += "]";

    log.debug("generateTable( columnNames = " + Arrays.toString(columnNames) + ", filterOptions = "
            + filterString + ")");

    tablePanel.removeAll();
    int columnNamesLength = columnNames.length;
    if (!getCanDelete())
        columnNamesLength++;
    MyTableModel dataModel = new MyTableModel(1, columnNamesLength + 2) {

        private static final long serialVersionUID = 1348355328684460769L;

        @Override
        public boolean isCellEditable(int row, int column) {
            return column != 0 && !invisibleFilterCols.contains(column);
        }
    };
    filters = new JTable(dataModel) {

        private static final long serialVersionUID = -8266991359840905405L;

        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component c = super.prepareRenderer(renderer, row, column);

            if (isCellEditable(row, column) && column != getColumnCount() - 1) {
                if (c instanceof JTextField) {
                    ((JTextField) c).setBorder(new MatteBorder(1, 1, 1, 1, Color.BLACK));
                } else if (c instanceof JComboBox) {
                    ((JComboBox) c).setBorder(new MatteBorder(1, 1, 1, 1, Color.BLACK));
                } else if (c instanceof JLabel) {
                    ((JLabel) c).setBorder(new MatteBorder(1, 1, 1, 1, Color.BLACK));
                }
            }
            return c;
        }
    };
    filters.setSurrendersFocusOnKeystroke(true);
    filters.setShowGrid(false);
    filters.setRowHeight(22);
    filters.setOpaque(false);

    for (Integer i = 0; i < filterOptions.length; i++) {
        final Object[] items = filterOptions[i];
        if (items != null && items.length > 1) {
            setComboBoxEditor(i, items);
        } else {
            final DefaultCellEditor defaultCellEditor = new DefaultCellEditor(new JTextField());
            defaultCellEditor.setClickCountToStart(1);
            filters.getColumnModel().getColumn(i + 1).setCellEditor(defaultCellEditor);
        }
    }

    filters.setRowSelectionAllowed(false);
    filters.setDragEnabled(false);
    filters.setColumnSelectionAllowed(false);
    filters.setDefaultEditor(JButton.class, new JButtonCellEditor());

    filters.setDefaultRenderer(Object.class, new DefaultTableRenderer() {
        private static final long serialVersionUID = -4811729559786534118L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (invisibleFilterCols.contains(column))
                c = new JLabel("");
            return c;
        }

    });

    filters.setDefaultRenderer(JButton.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JButton b = (JButton) value;
            b.setBorderPainted(false);
            b.setContentAreaFilled(false);
            return b;
        }
    });
    filters.setDefaultRenderer(JLabel.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            return (JLabel) value;
        }
    });
    filters.setDefaultEditor(JButton.class, new JButtonCellEditor());
    filters.getModel().setValueAt(new JLabel(""), 0, 0);
    JButton jButton2 = new JButton(noFiltrarAction);
    JButton jButton = new JButton(filtrarAction);
    jButton.setBorderPainted(false);
    jButton2.setBorderPainted(false);
    jButton.setContentAreaFilled(false);
    jButton2.setContentAreaFilled(false);
    if (jButton.getIcon() != null)
        jButton.setPreferredSize(
                new Dimension(jButton.getIcon().getIconWidth(), jButton.getIcon().getIconHeight()));
    if (jButton2.getIcon() != null)
        jButton2.setPreferredSize(
                new Dimension(jButton2.getIcon().getIconWidth(), jButton2.getIcon().getIconHeight()));

    filters.getModel().setValueAt(jButton, 0, columnNamesLength - 1);
    filters.getColumnModel().getColumn(columnNamesLength - 1).setMinWidth(jButton.getWidth() + 24);
    filters.getModel().setValueAt(jButton2, 0, columnNamesLength);
    filters.getColumnModel().getColumn(columnNamesLength).setMinWidth(jButton2.getWidth() + 14);
    cuenta.setHorizontalAlignment(JLabel.CENTER);
    cuenta.setText("?/?");
    filters.getModel().setValueAt(cuenta, 0, columnNamesLength + 1);

    tablePanel.add(filters, BorderLayout.NORTH);

    Vector<String> headers = new Vector<String>();
    headers.add("");
    headers.addAll(Arrays.asList(columnNames));
    MyTableModel model = new MyTableModel(headers, 0);
    table = new JTable(model) {

        private static final long serialVersionUID = 949284378605881770L;
        private int highLightedRow = -1;
        private Rectangle dirtyRegion = null;

        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component c = super.prepareRenderer(renderer, row, column);
            try {
                if (AdminPanel.this.myRendererColoring != null)
                    c.setBackground(AdminPanel.this.myRendererColoring
                            .getColor(AdminPanel.this.table.getValueAt(row, 1)));
            } catch (Throwable t) {
                log.error("Error al colorear la celda: " + t);
            }
            return c;
        }

        @Override
        protected void processMouseMotionEvent(MouseEvent e) {
            try {
                int row = rowAtPoint(e.getPoint());
                Graphics g = getGraphics();
                if (row == -1) {
                    highLightedRow = -1;
                }

                // row changed
                if (highLightedRow != row) {
                    if (null != dirtyRegion) {
                        paintImmediately(dirtyRegion);
                    }
                    for (int j = 0; j < getRowCount(); j++) {
                        if (row == j) {
                            // highlight
                            Rectangle firstRowRect = getCellRect(row, 0, false);
                            Rectangle lastRowRect = getCellRect(row, getColumnCount() - 1, false);
                            dirtyRegion = firstRowRect.union(lastRowRect);
                            g.setColor(new Color(0xff, 0xff, 0, 100));
                            g.fillRect((int) dirtyRegion.getX(), (int) dirtyRegion.getY(),
                                    (int) dirtyRegion.getWidth(), (int) dirtyRegion.getHeight());
                            highLightedRow = row;
                        }

                    }
                }
            } catch (Exception ex) {
            }
            super.processMouseMotionEvent(e);
        }
    };

    table.setRowHeight(22);

    table.setOpaque(false);
    // table.setAutoCreateRowSorter(true);

    table.setDragEnabled(false);
    table.getTableHeader().setReorderingAllowed(false);
    table.getTableHeader().setResizingAllowed(false);

    table.setDefaultEditor(JButton.class, new JButtonCellEditor());
    table.setDefaultRenderer(JButton.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JButton b = (JButton) value;
            if (b != null) {
                b.setBorderPainted(false);
                b.setContentAreaFilled(false);
            }
            return b;
        }
    });

    JScrollPane jScrollPane = new JScrollPane(table);
    jScrollPane.setOpaque(false);
    jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jScrollPane.getViewport().setOpaque(false);
    tablePanel.add(jScrollPane, BorderLayout.CENTER);
}

From source file:org.rdv.viz.image.ImageViz.java

private void initIrisControls() {
    irisControls = new JPanel();
    irisControls.setLayout(new BorderLayout());

    JButton closeIrisButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-close.gif"));
    closeIrisButton.setBorder(null);/*from   w w  w. ja v a 2s . c o m*/
    closeIrisButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            irisClose();
        }
    });
    irisControls.add(closeIrisButton, BorderLayout.WEST);

    JButton irisControlButton = new StrechIconButton(
            DataViewer.getIcon("icons/ptz/robotic_control-irisbar-medium.gif"));
    irisControlButton.setBorder(null);
    irisControlButton.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            JButton button = (JButton) e.getComponent();
            int iris = Math.round(100f * e.getPoint().x / button.getWidth());
            iris(iris);
        }
    });
    irisControls.add(irisControlButton, BorderLayout.CENTER);

    JPanel irisControlsRight = new JPanel();
    irisControlsRight.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));

    JButton openIrisButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-open.gif"));
    openIrisButton.setBorder(null);
    openIrisButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            irisOpen();
        }
    });
    irisControlsRight.add(openIrisButton);

    JButton autoIrisButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-auto.gif"));
    autoIrisButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            irisAuto();
        }
    });
    autoIrisButton.setBorder(null);
    irisControlsRight.add(autoIrisButton);

    irisControls.add(irisControlsRight, BorderLayout.EAST);
}

From source file:org.rdv.viz.image.ImageViz.java

private void initFocusControls() {
    focusControls = new JPanel();
    focusControls.setLayout(new BorderLayout());

    JButton nearFocusButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-near.gif"));
    nearFocusButton.setBorder(null);//from   w  w  w  .  j  ava  2  s.c o m
    nearFocusButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            focusNear();
        }
    });
    focusControls.add(nearFocusButton, BorderLayout.WEST);

    JButton focusControlButton = new StrechIconButton(
            DataViewer.getIcon("icons/ptz/robotic_control-focusbar-medium.gif"));
    focusControlButton.setBorder(null);
    focusControlButton.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            JButton button = (JButton) e.getComponent();
            int focus = Math.round(100f * e.getPoint().x / button.getWidth());
            focus(focus);
        }
    });

    focusControls.add(focusControlButton, BorderLayout.CENTER);

    JPanel focusControlsRight = new JPanel();
    focusControlsRight.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));

    JButton farFocusButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-far.gif"));
    farFocusButton.setBorder(null);
    farFocusButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            focusFar();
        }
    });
    focusControlsRight.add(farFocusButton);

    JButton autoFocusButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-auto.gif"));
    autoFocusButton.setBorder(null);
    autoFocusButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            focusAuto();
        }
    });
    focusControlsRight.add(autoFocusButton);

    focusControls.add(focusControlsRight, BorderLayout.EAST);
}

From source file:org.rdv.viz.image.ImageViz.java

private void initZoomControls() {
    zoomControls = new JPanel();
    zoomControls.setLayout(new BorderLayout());

    JButton zoomOutButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-minus.gif"));
    zoomOutButton.setBorder(null);//from  w ww.jav a2  s .  c  o m
    zoomOutButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            zoomOut();
        }
    });
    zoomControls.add(zoomOutButton, BorderLayout.WEST);

    JButton zoomControlButton = new StrechIconButton(
            DataViewer.getIcon("icons/ptz/robotic_control-zoombar-medium.gif"));
    zoomControlButton.setBorder(null);
    zoomControlButton.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            JButton button = (JButton) e.getComponent();
            int zoom = Math.round(100f * e.getPoint().x / button.getWidth());
            zoom(zoom);
        }
    });
    zoomControls.add(zoomControlButton, BorderLayout.CENTER);

    JPanel topRightControls = new JPanel();
    topRightControls.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));

    JButton zoomInButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-plus.gif"));
    zoomInButton.setBorder(null);
    zoomInButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            zoomIn();
        }
    });
    topRightControls.add(zoomInButton);

    JButton topHomeButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-home.gif"));
    topHomeButton.setBorder(null);
    topHomeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            home();
        }
    });
    topRightControls.add(topHomeButton);

    zoomControls.add(topRightControls, BorderLayout.EAST);
}

From source file:org.rdv.viz.image.ImageViz.java

private void initPanControls() {
    panControls = new JPanel();
    panControls.setLayout(new BorderLayout());

    JButton panLeftButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-left.gif"));
    panLeftButton.setBorder(null);// ww  w .  java  2 s. c  om
    panLeftButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            panLeft();
        }
    });
    panControls.add(panLeftButton, BorderLayout.WEST);

    JButton panControlButton = new StrechIconButton(
            DataViewer.getIcon("icons/ptz/robotic_control-panbar-medium.gif"));
    panControlButton.setBorder(null);
    panControlButton.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            JButton button = (JButton) e.getComponent();
            int pan = Math.round(100f * e.getPoint().x / button.getWidth());
            pan(pan);
        }
    });
    panControls.add(panControlButton, BorderLayout.CENTER);

    JPanel bottomRightControls = new JPanel();
    bottomRightControls.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));

    JButton panRightButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-right.gif"));
    panRightButton.setBorder(null);
    panRightButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            panRight();
        }
    });
    bottomRightControls.add(panRightButton);

    JButton bottomHomeButton = new JButton(DataViewer.getIcon("icons/ptz/robotic_control-home.gif"));
    bottomHomeButton.setBorder(null);
    bottomHomeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            home();
        }
    });
    bottomRightControls.add(bottomHomeButton);

    panControls.add(bottomRightControls, BorderLayout.EAST);
}