Example usage for javax.swing JButton setOpaque

List of usage examples for javax.swing JButton setOpaque

Introduction

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

Prototype

@BeanProperty(expert = true, description = "The component's opacity")
public void setOpaque(boolean isOpaque) 

Source Link

Document

If true the component paints every pixel within its bounds.

Usage

From source file:XAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth();
            int height = getHeight() - insets.top - insets.bottom;
            int halfHeight = height / 2 + insets.top;
            g.drawLine(0, halfHeight, width, halfHeight);
        }//w ww .j ava 2 s.  c om
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentY(Component.TOP_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentY(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentY(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentY(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    container.add(button);

    return container;
}

From source file:YAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth() - insets.left - insets.right;
            int halfWidth = width / 2 + insets.left;
            int height = getHeight();
            int halfHeight = height / 2 + insets.top;
            g.drawLine(halfWidth, 0, halfWidth, height);
        }/*from   w  ww . j a  va2  s.com*/
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.LEFT_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentX(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentX(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    container.add(button);

    return container;
}

From source file:Main.java

/**
 * Fixes button opacity issues./*from  www.  j  a  v  a 2 s .  c om*/
 * This is particularly a problem with JButton on Macintosh;
 * when the background color of its container is changed,
 * a button will appear to be sitting on a gray rectangle.
 *
 * @param button
 */
public static void fixButtonOpacity(JButton button) {
    // If the LAF isn't Metal or a derivative, setOpaque( false ) for the button
    if (!(UIManager.getLookAndFeel() instanceof MetalLookAndFeel)) {
        button.setOpaque(false);
    }
}

From source file:net.sf.texprinter.utils.UIUtils.java

/**
 * Formats a button to a label with wider margins. In short, this
 * method is similar to the button/label one, but with wider margins.
 *
 * @param button The button. Nothing new here.
 *//* w  w  w.  j  a v a 2s . c o m*/
public static void formatButtonAsList(JButton button) {

    // disable focus paint
    button.setFocusPainted(false);

    // fix the margins
    button.setMargin(new Insets(0, 0, 0, 5));

    // disable content area fill
    button.setContentAreaFilled(false);

    // disable border paint
    button.setBorderPainted(false);

    // disable property
    button.setOpaque(false);
}

From source file:net.sf.texprinter.utils.UIUtils.java

/**
 * Formats a JButton as a JLabel. In some cases, I just want the a
 * JButton component to act as a JLabel, so this method does this
 * for me.//ww w .  ja v a  2 s  .  co m
 *
 * @param button The button. Some makeup is made to the button, so
 * it will look as a good old JLabel component.
 */
public static void formatButtonAsLabel(JButton button) {

    // disable focus paint
    button.setFocusPainted(false);

    // redefine margins
    button.setMargin(new Insets(0, 0, 0, 0));

    // disable content area fill
    button.setContentAreaFilled(false);

    // disable border paint
    button.setBorderPainted(false);

    // disable property
    button.setOpaque(false);
}

From source file:cool.pandora.modeller.ui.BagTableFormBuilder.java

/**
 * addBinding.//from  www .ja  v  a 2  s  .com
 *
 * @param isRequired   boolean
 * @param labelName    String
 * @param component    JComponent
 * @param removeButton JComponent
 * @return JComponent
 */
private JComponent[] addBinding(final boolean isRequired, final String labelName, final JComponent component,
        final JComponent removeButton) {
    removeButton.setFocusable(false);
    final JLabel label = new JLabel(labelName); // createLabelFor(fieldName,
    // component);
    label.setToolTipText("Double-Click to Edit");
    final TableLayoutBuilder layoutBuilder = getLayoutBuilder();
    if (!layoutBuilder.hasGapToLeft()) {
        layoutBuilder.gapCol();
    }
    layoutBuilder.cell(label, "colSpec=left:pref:noGrow");
    final JComponent reqComp;
    /* */
    if (isRequired) {
        final JButton b = new JButton("R");
        b.setForeground(Color.red);
        b.setOpaque(false);
        b.setBorderPainted(false);
        reqComp = b;
    } else {
        final JButton b = new JButton("");
        b.setOpaque(false);
        b.setBorderPainted(false);
        reqComp = b;
    }
    /* */
    reqComp.setFocusable(false);
    layoutBuilder.cell(reqComp, "colSpec=left:pref:noGrow");
    layoutBuilder.cell(component, "colSpec=fill:pref:grow");
    layoutBuilder.labelGapCol();
    layoutBuilder.cell(removeButton, "colSpec=left:pref:noGrow");
    layoutBuilder.labelGapCol();
    return new JComponent[] { label, reqComp, component, removeButton };
}

From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java

public JButton createJButton(String text, String toolTip, String type) {
    JButton jbn = null;
    if (type.equals("icon")) {
        jbn = new JButton(createGeneralIcon(text));
    } else if (type.equals("text")) {
        Font jbnFont = new Font(Font.SANS_SERIF, Font.BOLD, 10);
        jbn = new JButton(text);
        jbn.setFont(jbnFont);//from   w  w  w .ja  v a  2  s .c  om
    }
    jbn.setOpaque(true);
    jbn.setToolTipText(toolTip);
    return jbn;
}

From source file:cool.pandora.modeller.ui.jpanel.base.BagInfoForm.java

private void createFormFieldsFromMap(final BagTableFormBuilder formBuilder) {
    int rowCount = 0;
    final int index = 2;

    final Set<String> keys = fieldMap.keySet();
    for (final BagInfoField field : fieldMap.values()) {
        formBuilder.row();/*from  ww  w  .  j a  v  a 2s . c o  m*/
        rowCount++;
        final ImageIcon imageIcon = bagView.getPropertyImage("bag.delete.image");
        JButton removeButton = new JButton(imageIcon);
        final Dimension dimension = removeButton.getPreferredSize();
        dimension.width = imageIcon.getIconWidth();
        removeButton.setMaximumSize(dimension);
        removeButton.setOpaque(false);
        removeButton.setBorderPainted(false);
        removeButton.setContentAreaFilled(false);
        removeButton.addActionListener(new RemoveFieldHandler());
        logger.debug("OrganizationInfoForm add: " + field);
        if (field.getValue() != null && field.getValue().length() > 60) {
            field.setComponentType(BagInfoField.TEXTAREA_COMPONENT);
        }
        if (field.isRequired()) {
            removeButton = new JButton();
            removeButton.setOpaque(false);
            removeButton.setBorderPainted(false);
            removeButton.setContentAreaFilled(false);
        }
        switch (field.getComponentType()) {
        case BagInfoField.TEXTAREA_COMPONENT:
            final JComponent[] tlist = formBuilder.addTextArea(field.isRequired(), field.getLabel(),
                    removeButton);
            final JComponent textarea = tlist[index];
            textarea.setEnabled(field.isEnabled());
            textarea.addFocusListener(this);
            ((NoTabTextArea) textarea).setText(field.getValue());
            textarea.setBorder(new EmptyBorder(1, 1, 1, 1));
            ((NoTabTextArea) textarea).setLineWrap(true);
            if (rowCount == 1) {
                focusField = textarea;
            }
            break;
        case BagInfoField.TEXTFIELD_COMPONENT:
            final JComponent[] flist = formBuilder.add(field.isRequired(), field.getLabel(), removeButton);
            final JComponent comp = flist[index];
            comp.setEnabled(field.isEnabled());
            comp.addFocusListener(this);
            ((JTextField) comp).setText(field.getValue());
            if (rowCount == 1) {
                focusField = comp;
            }
            break;
        case BagInfoField.LIST_COMPONENT:
            final List<String> elements = field.getElements();
            final JComponent[] llist = formBuilder.addList(field.isRequired(), field.getLabel(), elements,
                    field.getValue(), removeButton);
            final JComponent lcomp = llist[index];
            lcomp.setEnabled(field.isEnabled());
            lcomp.addFocusListener(this);
            if (field.getValue() != null) {
                ((JComboBox<?>) lcomp).setSelectedItem(field.getValue().trim());
            }
            if (rowCount == 1) {
                focusField = lcomp;
            }
            break;
        default:
        }
    }
    if (focusField != null) {
        focusField.requestFocus();
    }

}

From source file:Interface.Stats.java

/**
 *
 * @param f // w  ww.  j a v a 2s  .  co  m
 */
private Stats(JFrame f) {
    // On initialise les boutons
    JButton valider = new JButton("Valider");
    JButton retour = new JButton("Retour");
    JComboBox combo = new JComboBox();

    // On initialise et remplit la combobox
    combo.setPreferredSize(new Dimension(400, 30));
    combo.addItem("Nombre de patient par service");
    combo.addItem("Salaire moyen des employs");
    combo.addItem("Nombre d'intervention par mdecin");

    // On initialise les JLabels
    JLabel texte = new JLabel("Veuillez selectionner la requete  envoyer");

    // On change le bouton de forme
    valider.setPreferredSize(new Dimension(200, 30));
    valider.setOpaque(false);
    retour.setPreferredSize(new Dimension(200, 30));
    retour.setOpaque(false);

    // On initialise les Jpanels
    p1 = new JPanel();
    p1.setPreferredSize(new Dimension(600, 100));
    p1.add(texte);
    p1.setOpaque(false);

    p2 = new JPanel();
    p2.add(combo);
    p2.setOpaque(false);

    p4 = new JPanel();
    p4.add(retour);
    p4.add(valider);
    p4.setOpaque(false);

    // Gestion des boutons
    retour.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Accueil.getFenetre(f);
        }
    });

    valider.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (combo.getSelectedItem().equals("Nombre de patient par service")) {

                System.out.println(
                        "Nb de patients en REA : " + Connexion.getInstance().nb_malade_services("\"REA\""));
                System.out.println(
                        "Nb de patients en ORL : " + Connexion.getInstance().nb_malade_services("\"ORL\""));
                System.out.println(
                        "Nb de patients en CHG : " + Connexion.getInstance().nb_malade_services("\"CHG\""));

                //      new Camembert(f, Connexion.getInstance().nb_malade_services("\"REA\""), Connexion.getInstance().nb_malade_services("\"ORL\""), Connexion.getInstance().nb_malade_services("\"CHG\""));
                JPanel panel_camemb = Camembert.cCamembert(f,
                        Connexion.getInstance().nb_malade_services("\"REA\""),
                        Connexion.getInstance().nb_malade_services("\"ORL\""),
                        Connexion.getInstance().nb_malade_services("\"CHG\""));
                ;

                f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                f.add(p1);
                f.add(p2);
                f.add(p4);
                f.add(panel_camemb);

                f.setVisible(true);

            } else if (combo.getSelectedItem().equals("Salaire moyen des employs")) {
                JLabel jf_doc, jf_inf, jf_emp;
                JTextField jtf_doc, jtf_inf, jtf_emp;
                JPanel p5, p6, p7;

                // On initialise les JF
                jf_doc = new JLabel("Salaire moyen des docteurs");
                jf_inf = new JLabel("Salaire moyen des infirmiers");
                jf_emp = new JLabel("Salaire moyen de tous les employs");

                // On initialise les JTF
                jtf_doc = new JTextField();
                jtf_doc.setPreferredSize(new Dimension(200, 30));
                jtf_doc.setText(Float.toString(Connexion.getInstance().moyenne_salaired()) + " ");

                jtf_inf = new JTextField();
                jtf_inf.setPreferredSize(new Dimension(200, 30));
                jtf_inf.setText(Float.toString((Connexion.getInstance().moyenne_salairei())) + " ");

                jtf_emp = new JTextField();
                jtf_emp.setPreferredSize(new Dimension(160, 30));
                jtf_emp.setText(Float.toString((Connexion.getInstance().moyenne_salaire())) + " ");

                // On cre les JPanels
                p5 = new JPanel();
                p5.add(jf_doc);
                p5.add(jtf_doc);
                p5.setOpaque(false);

                p6 = new JPanel();
                p6.add(jf_inf);
                p6.add(jtf_inf);
                p6.setOpaque(false);

                p7 = new JPanel();
                p7.add(jf_emp);
                p7.add(jtf_emp);
                p7.setOpaque(false);

                f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                f.add(p1);
                f.add(p2);
                f.add(p4);
                f.add(p5);
                f.add(p6);
                f.add(p7);

                f.setVisible(true);
                f.setSize(new Dimension(600, 600));
            } else if (combo.getSelectedItem().equals("Nombre d'intervention par mdecin")) {
                ArrayList liste = null;
                try {
                    // ICI !!!!!!!!!!
                    liste = Connexion.getInstance().reporting(
                            "SELECT e.nom , COUNT(d.no_docteur) FROM hospitalisation h, docteur d , employe e WHERE (h.no_docteur= d.no_docteur) AND e.no_employe = d.no_docteur  GROUP BY e.nom");
                } catch (SQLException ex) {
                    Logger.getLogger(Stats.class.getName()).log(Level.SEVERE, null, ex);
                }
                if (liste != null) {
                    JPanel panel_camemb = Camembert.cCamembert(f, liste);

                    f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                    f.add(p1);
                    f.add(p2);
                    f.add(p4);
                    f.add(panel_camemb);

                    f.setVisible(true);
                }

            }
        }
    });
}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java

private JPanel getOverlayPanel() {
    final JPanel overlayPanel = new JPanel();
    overlayPanel.setOpaque(false);//from w  w w  .  j a v a  2  s  .c o  m
    overlayPanel.setLayout(new GridBagLayout());
    filterTextField.addKeyListener(new KeyListener() {
        @Override
        public void keyTyped(final KeyEvent e) {

        }

        @Override
        public void keyReleased(final KeyEvent e) {
        }

        @Override
        public void keyPressed(final KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                hideFilter();
            }
        }
    });
    filterTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(final DocumentEvent e) {
            textChanged();

        }

        @Override
        public void insertUpdate(final DocumentEvent e) {
            textChanged();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {

        }

        private void textChanged() {
            serverListModel.filter(filterTextField.getText());
        }
    });

    final SearchField searchField = new SearchField(filterTextField);

    final ImageIcon closeIcon = Utils.icon("cross16.png");
    final JButton closeButton = new JButton(closeIcon);
    closeButton.setBounds(10, 10, closeIcon.getIconWidth(), closeIcon.getIconHeight());
    closeButton.setMargin(new Insets(0, 0, 0, 0));
    closeButton.setOpaque(false);
    closeButton.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    closeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            hideFilter();
        }
    });

    searchPanel.add(searchField);
    searchPanel.add(closeButton);
    // searchPanel.setBorder(BorderFactory
    // .createBevelBorder(BevelBorder.RAISED));
    searchPanel.setBorder(BorderFactory.createEtchedBorder());
    searchPanel.setVisible(false);
    searchPanel.setAlignmentX(RIGHT_ALIGNMENT);

    final GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.LAST_LINE_END;
    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.insets = new Insets(3, 3, 3, 3);
    overlayPanel.add(searchPanel, c);
    return overlayPanel;
}