Example usage for javax.swing JPanel setOpaque

List of usage examples for javax.swing JPanel setOpaque

Introduction

In this page you can find the example usage for javax.swing JPanel 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:es.emergya.ui.gis.popups.SDSDialog.java

public SDSDialog(Recurso r) {
    super();//  w  ww .jav  a2s .  c om
    setAlwaysOnTop(true);
    setResizable(false);
    iconTransparente = LogicConstants.getIcon("48x48_transparente");
    iconEnviando = LogicConstants.getIcon("anim_enviando");
    destino = r;
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            cancel.doClick();
        }
    });

    // setPreferredSize(new Dimension(400, 150));
    setTitle(i18n.getString("window.sds.titleBar") + " " + r.getIdentificador());
    try {
        setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getIconImage());
    } catch (Throwable e) {
        LOG.error("There is no icon image", e);
    }

    JPanel base = new JPanel();

    base.setBackground(Color.WHITE);
    base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

    // Icono del titulo
    JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING));
    final JLabel titleLabel = new JLabel(i18n.getString("window.sds.title"),
            LogicConstants.getIcon("tittleventana_icon_enviarsds"), JLabel.LEFT);

    titleLabel.setFont(LogicConstants.deriveBoldFont(12f));
    title.add(titleLabel);
    title.setOpaque(false);
    base.add(title);

    // Espacio para el mensaje
    sds = new JTextArea(7, 40);
    sds.setLineWrap(true);

    final JScrollPane sdsp = new JScrollPane(sds);

    sdsp.setOpaque(false);
    sdsp.setBorder(new TitledBorder(BorderFactory.createLineBorder(Color.BLACK),
            i18n.getString("Admin.message") + "\t (0/" + maxChars + ")"));
    sds.setDocument(new PlainDocument() {
        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            if (this.getLength() + str.length() <= maxChars) {
                super.insertString(offs, str, a);
            }
        }
    });
    sds.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateChars(e);
        }

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateChars(e);
        }

        private void updateChars(DocumentEvent e) {
            ((TitledBorder) sdsp.getBorder()).setTitle(
                    i18n.getString("Admin.message") + "\t (" + sds.getText().length() + "/" + maxChars + ")");
            sdsp.repaint();
            send.setEnabled(!sds.getText().isEmpty());
            notification.setForeground(Color.WHITE);
            notification.setText("PLACEHOLDER");
        }
    });
    base.add(sdsp);

    // Area para mensajes
    JPanel notificationArea = new JPanel();

    notificationArea.setOpaque(false);
    notification = new JLabel("TEXT");
    notification.setForeground(Color.WHITE);
    notificationArea.add(notification);
    base.add(notificationArea);

    JPanel buttons = new JPanel();

    buttons.setOpaque(false);
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
    send = new JButton(i18n.getString("Buttons.send"),
            LogicConstants.getIcon("ventanacontextual_button_enviarsds"));
    send.addActionListener(this);
    send.setEnabled(false);
    buttons.add(send);
    buttons.add(Box.createHorizontalGlue());
    progressIcon = new JLabel(iconTransparente);
    buttons.add(progressIcon);
    buttons.add(Box.createHorizontalGlue());
    cancel = new JButton(i18n.getString("Buttons.cancel"), LogicConstants.getIcon("button_cancel"));
    cancel.addActionListener(this);
    buttons.add(cancel);
    base.add(buttons);
    getContentPane().add(base);
    pack();

    int x;
    int y;
    Container myParent;
    try {
        myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getContentPane();
        java.awt.Point topLeft = myParent.getLocationOnScreen();
        Dimension parentSize = myParent.getSize();

        Dimension mySize = getSize();

        if (parentSize.width > mySize.width)
            x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
        else
            x = topLeft.x;

        if (parentSize.height > mySize.height)
            y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
        else
            y = topLeft.y;

        setLocation(x, y);
    } catch (Throwable e1) {
        LOG.error("There is no basic window!", e1);
    }
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent arg0) {
            deleteErrorMessage();
        }

        @Override
        public void windowClosed(WindowEvent arg0) {
            deleteErrorMessage();
        }

        private void deleteErrorMessage() {
            SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {
                @Override
                protected Object doInBackground() throws Exception {
                    if (bandejaSalida != null) {
                        MessageGenerator.remove(bandejaSalida.getId());
                    }

                    bandejaSalida = null;

                    return null;
                }

                @Override
                protected void done() {
                    super.done();
                    SDSDialog.this.sds.setText("");
                    SDSDialog.this.sds.setEnabled(true);
                    SDSDialog.this.sds.repaint();
                    SDSDialog.this.progressIcon.setIcon(iconTransparente);
                    SDSDialog.this.progressIcon.repaint();
                    SDSDialog.this.notification.setText("");
                    SDSDialog.this.notification.repaint();
                }
            };

            sw.execute();
        }
    });
}

From source file:com.polivoto.vistas.Charts.java

private JPanel hacerTabla(Pregunta pregunta, List<Opcion> opciones, String perfil) {
    Tabla panel = new Tabla();
    //Panel completo
    //scrollPanel.setBackground(Color.blue);

    //Ttulo pregunta
    JLabel tituloPregunta = new JLabel("\t" + pregunta.getTitulo() + " (" + perfil + ")");
    tituloPregunta.setFont(new Font("Roboto", 1, 24));
    tituloPregunta.setForeground(Color.black);
    tituloPregunta.setVerticalAlignment(JLabel.CENTER);
    JPanel panelHeader = panel.getjPanelHead();
    panelHeader.add(tituloPregunta);//from  w  w  w  .  j  a  v a2 s.  c  o m
    panelHeader.setOpaque(false);
    panelHeader.setPreferredSize(panelGrafica.getSize());

    //Panel de la tabla
    JPanel tabla = new JPanel(new GridLayout(pregunta.obtenerCantidadDeOpciones() + 2, 3, 5, 5));
    tabla.setBackground(Color.white);

    //Poner el titulo de cada columna
    for (int i = 0; i < 3; i++) {
        JPanel tilt = new JPanel();
        tilt.setBackground(new Color(137, 36, 31));
        JLabel label = new JLabel(i == 0 ? "Opcion" : i == 2 ? "Porcentaje" : "Cantidad");
        label.setFont(new Font("Roboto", 1, 18));
        label.setForeground(Color.white);
        tilt.add(label);
        tilt.setSize(new Dimension(0, 35));
        tilt.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
        tabla.add(tilt);
    }

    int sum = 0;

    for (Opcion opcion : opciones) {
        sum += opcion.getCantidad();
    }

    for (Opcion opc : opciones) {
        JPanel p1 = new JPanel(new GridLayout(0, 1));
        p1.setBackground(Color.white);
        p1.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
        JTextArea l1 = new JTextArea(opc.getNombre());

        l1.setWrapStyleWord(true);
        l1.setLineWrap(true);
        l1.setFont(new Font("Roboto", 0, 18));
        l1.setEditable(false);
        l1.setBorder(null);
        p1.setPreferredSize(l1.getSize());
        p1.add(l1);
        tabla.add(p1);

        JPanel p2 = new JPanel();
        p2.setBackground(Color.white);
        p2.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
        JLabel l2 = new JLabel("" + opc.getCantidad());
        l2.setFont(new Font("Roboto", 0, 18));
        p2.add(l2);
        tabla.add(p2);

        JPanel p3 = new JPanel();
        p3.setBackground(Color.white);
        p3.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
        double porcentaje = (opc.getCantidad() * 100.0) / sum;
        JLabel l3 = new JLabel(String.format("%.2f", porcentaje) + "%");
        l3.setFont(new Font("Roboto", 0, 18));
        p3.add(l3);
        tabla.add(p3);
    }

    JPanel p1 = new JPanel();
    p1.setBackground(Color.white);
    p1.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
    JLabel l1 = new JLabel("Total");
    l1.setHorizontalTextPosition(JLabel.LEFT);
    l1.setFont(new Font("Roboto", 1, 18));
    p1.add(l1);
    tabla.add(p1);

    JPanel p2 = new JPanel();
    p2.setBackground(Color.white);
    p2.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
    JLabel l2 = new JLabel("" + sum);
    l2.setFont(new Font("Roboto", 1, 18));
    p2.add(l2);
    tabla.add(p2);

    JPanel p3 = new JPanel();
    p3.setBackground(Color.white);
    p3.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
    JLabel l3 = new JLabel("100.00%");
    l3.setFont(new Font("Roboto", 1, 18));
    p3.add(l3);
    tabla.add(p3);

    panel.getjPanelContent().add(tabla, BorderLayout.CENTER);

    //Relleno
    JPanel x = new JPanel(new GridLayout());
    x.setPreferredSize(new Dimension(100, 0));
    x.setBackground(Color.white);
    panel.getjPanelContent().add(x, BorderLayout.LINE_START);
    JPanel y = new JPanel(new GridLayout());
    y.setPreferredSize(new Dimension(100, 0));
    y.setBackground(Color.white);
    panel.getjPanelContent().add(y, BorderLayout.LINE_END);
    JPanel z = new JPanel(new GridLayout());
    z.setBackground(Color.white);
    z.setPreferredSize(new Dimension(0, 40));
    panel.getjPanelContent().add(z, BorderLayout.PAGE_END);

    return panel;
}

From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileGraphicDetailPanel.java

private JPanel createInstantDataPanel() {
    I18nLabel timeLabel = new I18nLabel("dive.time");
    instantDepthLabel = new JLabel();
    setDephtLabelText();/*from  ww w  .  j  a va2s  .c o m*/

    instantTimeTf = new JTextField(6);
    instantTimeTf.setText(null);
    instantTimeTf.setEditable(false);
    instantTimeTf.setFocusable(false);

    instantDepthTf = new JTextField(6);
    instantDepthTf.setText(null);
    instantDepthTf.setEditable(false);
    instantDepthTf.setFocusable(false);

    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(3, 3, 3, 3);

    JPanel instantDataPanel = new DetailPanel();
    instantDataPanel.setLayout(new GridBagLayout());
    instantDataPanel.setOpaque(false);

    GridBagLayoutManager.addComponent(instantDataPanel, timeLabel, c, 0, 0, 1, 1, 0, 0, GridBagConstraints.NONE,
            GridBagConstraints.WEST);
    GridBagLayoutManager.addComponent(instantDataPanel, instantTimeTf, c, 1, 0, 1, 1, 1, 0,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);

    GridBagLayoutManager.addComponent(instantDataPanel, instantDepthLabel, c, 0, 1, 1, 1, 0, 0,
            GridBagConstraints.NONE, GridBagConstraints.WEST);
    GridBagLayoutManager.addComponent(instantDataPanel, instantDepthTf, c, 1, 1, 1, 1, 1, 0,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);

    return instantDataPanel;
}

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

private JPanel getOverlayPanel() {
    final JPanel overlayPanel = new JPanel();
    overlayPanel.setOpaque(false);
    overlayPanel.setLayout(new GridBagLayout());
    filterTextField.addKeyListener(new KeyListener() {
        @Override/*from  w w  w. ja  v a2 s  . co m*/
        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;
}

From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java

/**
 * Build content for animationType StatisticGrafic.ANIMATION_LastValue
 * @return/* ww  w  .  j a va2s  . co m*/
 */
private JPanel buildLastValuePanel() {
    JPanel out = new JPanel();
    out.setBackground(Grafic.COLOR_BACKGROUND);
    out.setOpaque(true);
    out.setLayout(new BorderLayout());
    switch (this.statistic.getTypeIndex()) {
    case Statistic.INDEX_None:
        this.valueLabel = new JLabel();
        this.valueLabel.setFont(Grafic.FONT_BIG);
        this.valueLabel.setForeground(Grafic.COLOR_FOREGROUND);
        out.add(this.valueLabel, BorderLayout.CENTER);
        if (this.isIntValue)
            out.setPreferredSize(new Dimension(80, 50));
        else
            out.setPreferredSize(new Dimension(100, 50));
        break;
    case Statistic.INDEX_Min_Max:
        this.valueLabel = new JLabel();
        this.valueLabel.setFont(Grafic.FONT_BIG);
        this.valueLabel.setForeground(Grafic.COLOR_FOREGROUND);
        out.add(this.valueLabel, BorderLayout.CENTER);
        ;
        Box top = Box.createVerticalBox();
        this.minLabel = new JLabel();
        this.minLabel.setFont(Grafic.FONT_DEFAULT);
        this.minLabel.setForeground(Grafic.COLOR_FOREGROUND);
        top.add(this.minLabel);
        this.maxLabel = new JLabel();
        this.maxLabel.setFont(Grafic.FONT_DEFAULT);
        this.maxLabel.setForeground(Grafic.COLOR_FOREGROUND);
        top.add(this.maxLabel);
        out.add(top, BorderLayout.SOUTH);
        if (this.isIntValue)
            out.setPreferredSize(new Dimension(80, 70));
        else
            out.setPreferredSize(new Dimension(100, 70));
        break;
    case Statistic.INDEX_Mean_StdDev:
        this.valueLabel = new JLabel();
        this.valueLabel.setFont(Grafic.FONT_BIG);
        this.valueLabel.setForeground(Grafic.COLOR_FOREGROUND);
        out.add(this.valueLabel, BorderLayout.CENTER);
        ;
        Box bottom = Box.createVerticalBox();
        this.meanLabel = new JLabel();
        this.meanLabel.setFont(Grafic.FONT_DEFAULT);
        this.meanLabel.setForeground(Grafic.COLOR_FOREGROUND);
        bottom.add(this.meanLabel);
        this.stdDevLabel = new JLabel();
        this.stdDevLabel.setFont(Grafic.FONT_DEFAULT);
        this.stdDevLabel.setForeground(Grafic.COLOR_FOREGROUND);
        bottom.add(this.stdDevLabel);
        out.add(bottom, BorderLayout.SOUTH);
        if (this.isIntValue)
            out.setPreferredSize(new Dimension(80, 70));
        else
            out.setPreferredSize(new Dimension(100, 70));
        break;
    }
    return out;
}

From source file:lol.search.RankedStatsPage.java

private JPanel bodyPanel(JPanel body) {
    body.setLayout(new BoxLayout(body, BoxLayout.X_AXIS));
    body.setBackground(backgroundColor);
    body.setPreferredSize(new Dimension(1200, 530));

    //load art /*from www  . j  a  va 2s.c o m*/
    this.loadArtLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    this.loadArtLabel.setPreferredSize(new Dimension(290, 504));
    this.loadArtLabel.setIcon(OBJ_GAME_STATIC_DATA.initLoadingArt(champKeyList.get(0)));
    body.add(this.loadArtLabel);

    JPanel rightPanel = new JPanel(new FlowLayout());
    rightPanel.setPreferredSize(new Dimension(800, 514));
    rightPanel.setOpaque(false);
    //rightPanel.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));

    JPanel headerPanel = new JPanel();
    headerPanel.setLayout(new BoxLayout(headerPanel, BoxLayout.X_AXIS));
    headerPanel.setPreferredSize(new Dimension(910, 55));
    headerPanel.setOpaque(false);
    //headerPanel.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
    this.defaultHeader.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 40)); //custom font
    this.defaultHeader.setForeground(Color.WHITE);
    this.defaultHeader.setAlignmentX(Component.LEFT_ALIGNMENT);
    this.defaultHeader.setText(" Season Totals: ");
    this.nameHeader.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 40)); //custom font
    this.nameHeader.setForeground(valueOrange);
    this.nameHeader.setAlignmentX(Component.LEFT_ALIGNMENT);
    this.nameHeader.setText("Overall");
    this.titleHeader.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 16)); //custom font
    this.titleHeader.setForeground(new Color(255, 128, 0));
    this.titleHeader.setAlignmentX(Component.LEFT_ALIGNMENT);
    //nameHeader.setAlignmentY(Component.TOP_ALIGNMENT);
    titleHeader.setAlignmentY(Component.TOP_ALIGNMENT);
    headerPanel.add(defaultHeader);
    headerPanel.add(nameHeader);
    headerPanel.add(titleHeader);
    rightPanel.add(headerPanel);
    rightPanel.add(statsPanel());
    body.add(rightPanel);

    return body;
}

From source file:com.openbravo.pos.sales.JRetailTicketPreviewTicket.java

private JPanel getLabelPanel(String msg, Color colour) {
    JPanel panel = new JPanel();
    Font font = new Font("Verdana", Font.BOLD, 12);
    panel.setFont(font);/*from   w w w. j  ava2  s .  c o m*/
    panel.setOpaque(true);
    // panel.setBackground(Color.BLUE);
    JLabel label = new JLabel(msg, JLabel.LEFT);
    label.setForeground(colour);
    label.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    panel.add(label);

    return panel;
}

From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.preenchedor_formulario.PanelPreenchedorFormulario.java

private void criaInterfaceVisualEscalavel() {
    miBtnSalvar = new JMenuItem(XHTML_Panel.BTN_SALVAR);
    painel = new JPanel();
    textAreaSourceCode = new G_TextAreaSourceCode();
    // frameSilvinha.setJMenuBar(this.criaMenuBar());
    new OnChange(textAreaSourceCode, this);

    textAreaSourceCode.setTipoHTML();/*from  ww  w.  jav  a2s  .c  o  m*/
    textAreaSourceCode.setBorder(criaBorda(XHTML_Panel.COD_FONTE));

    painel.setLayout(new GridLayout(2, 1));
    setBackground(frameSilvinha.corDefault);

    Container contentPane = this;
    contentPane.setLayout(new GridLayout(1, 1));
    painel.add(textAreaSourceCode);

    JPanel panelBtnTabela = new JPanel();

    panelBtnTabela.setLayout(new BorderLayout());

    /*
     * Barra de botes
     */
    btnPanel = new JPanel();
    btnPanel.setLayout(null);
    btn_salvar = new JButton(XHTML_Panel.BTN_SALVAR);
    btn_salvar.setToolTipText(XHTML_Panel.DICA_SALVAR);
    btn_salvar.setBounds(10, 0, 150, 25);
    btnPanel.add(btn_salvar);

    btn_abrir = new JButton(XHTML_Panel.BTN_ABRIR);
    btn_abrir.setToolTipText(XHTML_Panel.DICA_ABRIR);
    btn_abrir.setBounds(165, 0, 150, 25);
    btnPanel.add(btn_abrir);

    btn_salvarComo = new JButton(XHTML_Panel.BTN_SALVAR_COMO);
    btn_salvarComo.setToolTipText(XHTML_Panel.DICA_SALVAR_COMO);
    btn_salvarComo.setBounds(320, 0, 150, 25);
    btnPanel.add(btn_salvarComo);

    btn_cancelar = new JButton(XHTML_Panel.TELA_ANTERIOR);
    btn_cancelar.setToolTipText(XHTML_Panel.DICA_TELA_ANTERIOR);
    btn_cancelar.setBounds(480, 0, 150, 25);
    btnPanel.add(btn_cancelar);

    btnPanel.setPreferredSize(new Dimension(430, 30));

    /*
     * Barra de correcao
     */
    btnAplicar = new JButton(XHTML_Panel.BTN_APLICAR);
    btnAplicar.setToolTipText(XHTML_Panel.DICA_BTN_APLICAR);
    btnAplicar.setEnabled(false);

    texto = new JTextField();

    texto.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    JPanel borda = new JPanel(new BorderLayout());
    JLabel lbl_texto = new JLabel(XHTML_Panel.ROTULO_TEXTO);
    lbl_texto.setToolTipText(XHTML_Panel.DICA_ROTULO_TEXTO);
    borda.add(lbl_texto, BorderLayout.WEST);
    borda.add(texto, BorderLayout.CENTER);
    borda.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
    borda.setOpaque(false);
    panelCorretor = new JPanel(new BorderLayout());
    panelCorretor.add(borda, BorderLayout.CENTER);
    panelCorretor.add(btnAplicar, BorderLayout.EAST);
    //panelCorretor.add(btnPanel, BorderLayout.WEST);
    panelCorretor.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    panelCorretor.setOpaque(false);

    /*
     * Tabela de erros
     */
    tabelaDeErros = new TabelaErros();
    scrollPaneTabela = new JScrollPane();
    scrollPaneTabela.setViewportView(tabelaDeErros);
    panelBtnTabela.add(panelCorretor, BorderLayout.NORTH);
    panelBtnTabela.add(scrollPaneTabela, BorderLayout.CENTER);
    panelBtnTabela.add(btnPanel, BorderLayout.SOUTH);
    scrollPaneTabela.setBorder(criaBorda(XHTML_Panel.LISTA_ERROS));
    painel.add(panelBtnTabela);

    btnPanel.setBackground(frameSilvinha.corDefault);

    if (!original) {
        reverter = new JButton("Reverter");
        reverter.setText(TradPainelRelatorio.REVERTER);
        reverter.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                TxtBuffer.setContent(TxtBuffer.getContentOriginal());
                frameSilvinha.showPainelPreencheCampo();
                setVisible(true);
            }
        });
        //reverter.setActionCommand("Reverter");
        reverter.setToolTipText(TradPainelRelatorio.DICA_REVERTER);
        reverter.getAccessibleContext().setAccessibleDescription(TradPainelRelatorio.DICA_REVERTER);
        reverter.getAccessibleContext().setAccessibleName(TradPainelRelatorio.DICA_REVERTER);
        reverter.setBounds(640, 0, 150, 25);
        btnPanel.add(reverter);
    }

    panelBtnTabela.setBackground(frameSilvinha.corDefault);
    painel.setBackground(frameSilvinha.corDefault);
    contentPane.setBackground(frameSilvinha.corDefault);
    scrollPaneTabela.setBackground(frameSilvinha.corDefault);
    textAreaSourceCode.setBackground(frameSilvinha.corDefault);
    miBtnSalvar.setEnabled(false);
    btn_salvar.setEnabled(false);
    salvaAlteracoes = TxtBuffer.getInstanciaSalvaAlteracoes(textAreaSourceCode.getTextPane(), btn_salvar,
            miBtnSalvar, frameSilvinha);
    contentPane.add(painel);
    // pack();
    this.setVisible(true);
}

From source file:es.emergya.ui.plugins.admin.aux1.RecursoDialog.java

public RecursoDialog(final Recurso rec, final AdminResources adminResources) {
    super();//w w w .  j  ava2 s  .  co m
    setAlwaysOnTop(true);
    setSize(600, 400);

    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            if (cambios) {
                int res = JOptionPane.showConfirmDialog(RecursoDialog.this,
                        "Existen cambios sin guardar. Seguro que desea cerrar la ventana?",
                        "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION);
                if (res != JOptionPane.CANCEL_OPTION) {
                    e.getWindow().dispose();
                }
            } else {
                e.getWindow().dispose();
            }
        }
    });
    final Recurso r = (rec == null) ? null : RecursoConsultas.get(rec.getId());
    if (r != null) {
        setTitle(i18n.getString("Resources.summary.titleWindow") + " " + r.getIdentificador());
    } else {
        setTitle(i18n.getString("Resources.summary.titleWindow.new"));
    }
    setIconImage(getBasicWindow().getFrame().getIconImage());
    JPanel base = new JPanel();
    base.setBackground(Color.WHITE);
    base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

    // Icono del titulo
    JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING));
    title.setOpaque(false);
    JLabel labelTitulo = null;
    if (r != null) {
        labelTitulo = new JLabel(i18n.getString("Resources.summary"),
                LogicConstants.getIcon("tittleficha_icon_recurso"), JLabel.LEFT);

    } else {
        labelTitulo = new JLabel(i18n.getString("Resources.cabecera.nuevo"),
                LogicConstants.getIcon("tittleficha_icon_recurso"), JLabel.LEFT);

    }
    labelTitulo.setFont(LogicConstants.deriveBoldFont(12f));
    title.add(labelTitulo);
    base.add(title);

    // Nombre
    JPanel mid = new JPanel(new SpringLayout());
    mid.setOpaque(false);
    mid.add(new JLabel(i18n.getString("Resources.name"), JLabel.RIGHT));
    final JTextField name = new JTextField(25);
    if (r != null) {
        name.setText(r.getNombre());
    }

    name.getDocument().addDocumentListener(changeListener);
    name.setEditable(r == null);
    mid.add(name);

    // patrullas
    final JLabel labelSquads = new JLabel(i18n.getString("Resources.squad"), JLabel.RIGHT);
    mid.add(labelSquads);
    List<Patrulla> pl = PatrullaConsultas.getAll();
    pl.add(0, null);
    final JComboBox squads = new JComboBox(pl.toArray());
    squads.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXX");
    squads.addActionListener(changeSelectionListener);
    squads.setOpaque(false);
    labelSquads.setLabelFor(squads);
    if (r != null) {
        squads.setSelectedItem(r.getPatrullas());
    } else {
        squads.setSelectedItem(null);
    }
    squads.setEnabled((r != null && r.getHabilitado() != null) ? r.getHabilitado() : true);
    mid.add(squads);

    // // Identificador
    // mid.setOpaque(false);
    // mid.add(new JLabel(i18n.getString("Resources.identificador"),
    // JLabel.RIGHT));
    // final JTextField identificador = new JTextField("");
    // if (r != null) {
    // identificador.setText(r.getIdentificador());
    // }
    // identificador.getDocument().addDocumentListener(changeListener);
    // identificador.setEditable(r == null);
    // mid.add(identificador);
    // Espacio en blanco
    // mid.add(Box.createHorizontalGlue());
    // mid.add(Box.createHorizontalGlue());

    // Tipo
    final JLabel labelTipoRecursos = new JLabel(i18n.getString("Resources.type"), JLabel.RIGHT);
    mid.add(labelTipoRecursos);
    final JComboBox types = new JComboBox(RecursoConsultas.getTipos());
    labelTipoRecursos.setLabelFor(types);
    types.addActionListener(changeSelectionListener);
    if (r != null) {
        types.setSelectedItem(r.getTipo());
    } else {
        types.setSelectedItem(0);
    }
    // types.setEditable(true);
    types.setEnabled(true);
    mid.add(types);

    // Estado Eurocop
    mid.add(new JLabel(i18n.getString("Resources.status"), JLabel.RIGHT));
    final JTextField status = new JTextField();
    if (r != null && r.getEstadoEurocop() != null) {
        status.setText(r.getEstadoEurocop().getIdentificador());
    }
    status.setEditable(false);
    mid.add(status);

    // Subflota y patrulla
    mid.add(new JLabel(i18n.getString("Resources.subfleet"), JLabel.RIGHT));
    final JComboBox subfleets = new JComboBox(FlotaConsultas.getAllHabilitadas());
    subfleets.addActionListener(changeSelectionListener);
    if (r != null) {
        subfleets.setSelectedItem(r.getFlotas());
    } else {
        subfleets.setSelectedIndex(0);
    }
    subfleets.setEnabled(true);
    subfleets.setOpaque(false);
    mid.add(subfleets);

    // Referencia humana
    mid.add(new JLabel(i18n.getString("Resources.incidences"), JLabel.RIGHT));
    final JTextField rhumana = new JTextField();
    // if (r != null && r.getIncidencias() != null) {
    // rhumana.setText(r.getIncidencias().getReferenciaHumana());
    // }
    rhumana.setEditable(false);
    mid.add(rhumana);

    // dispositivo
    mid.add(new JLabel(i18n.getString("Resources.device"), JLabel.RIGHT));
    final PlainDocument plainDocument = new PlainDocument() {

        private static final long serialVersionUID = 4929271093724956016L;

        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            if (this.getLength() + str.length() <= LogicConstants.LONGITUD_ISSI) {
                super.insertString(offs, str, a);
            }
        }
    };
    final JTextField issi = new JTextField(plainDocument, "", LogicConstants.LONGITUD_ISSI);
    plainDocument.addDocumentListener(changeListener);
    issi.setEditable(true);
    mid.add(issi);
    mid.add(new JLabel(i18n.getString("Resources.enabled"), JLabel.RIGHT));
    final JCheckBox enabled = new JCheckBox("", true);
    enabled.addActionListener(changeSelectionListener);
    enabled.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (enabled.isSelected()) {
                squads.setSelectedIndex(0);
            }
            squads.setEnabled(enabled.isSelected());
        }
    });
    enabled.setEnabled(true);
    enabled.setOpaque(false);
    if (r != null) {
        enabled.setSelected(r.getHabilitado());
    } else {
        enabled.setSelected(true);
    }
    if (r != null && r.getDispositivo() != null) {
        issi.setText(
                StringUtils.leftPad(String.valueOf(r.getDispositivo()), LogicConstants.LONGITUD_ISSI, '0'));
    }

    mid.add(enabled);

    // Fecha ultimo gps
    mid.add(new JLabel(i18n.getString("Resources.lastPosition"), JLabel.RIGHT));
    JTextField lastGPS = new JTextField();
    final Date lastGPSDateForRecurso = HistoricoGPSConsultas.lastGPSDateForRecurso(r);
    if (lastGPSDateForRecurso != null) {
        lastGPS.setText(SimpleDateFormat.getDateTimeInstance().format(lastGPSDateForRecurso));
    }
    lastGPS.setEditable(false);
    mid.add(lastGPS);

    // Espacio en blanco
    mid.add(Box.createHorizontalGlue());
    mid.add(Box.createHorizontalGlue());

    // informacion adicional
    JPanel infoPanel = new JPanel(new SpringLayout());
    final JTextField info = new JTextField(25);
    info.getDocument().addDocumentListener(changeListener);
    infoPanel.add(new JLabel(i18n.getString("Resources.info")));
    infoPanel.add(info);
    infoPanel.setOpaque(false);
    info.setOpaque(false);
    SpringUtilities.makeCompactGrid(infoPanel, 1, 2, 6, 6, 6, 18);

    if (r != null) {
        info.setText(r.getInfoAdicional());
    } else {
        info.setText("");
    }
    info.setEditable(true);

    // Espacio en blanco
    mid.add(Box.createHorizontalGlue());
    mid.add(Box.createHorizontalGlue());

    SpringUtilities.makeCompactGrid(mid, 5, 4, 6, 6, 6, 18);
    base.add(mid);
    base.add(infoPanel);

    JPanel buttons = new JPanel();
    buttons.setOpaque(false);
    JButton accept = null;
    if (r == null) {
        accept = new JButton("Crear", LogicConstants.getIcon("button_crear"));
    } else {
        accept = new JButton("Guardar", LogicConstants.getIcon("button_save"));
    }
    accept.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                if (cambios || r == null || r.getId() == null) {
                    boolean shithappens = true;
                    if ((r == null || r.getId() == null)) { // Estamos
                        // creando
                        // uno nuevo
                        if (RecursoConsultas.alreadyExists(name.getText())) {
                            shithappens = false;
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.nombreUnico"));
                        } else if (issi.getText() != null && issi.getText().length() > 0 && StringUtils
                                .trimToEmpty(issi.getText()).length() != LogicConstants.LONGITUD_ISSI) {
                            JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString(Locale.ROOT,
                                    "admin.recursos.popup.error.faltanCifras", LogicConstants.LONGITUD_ISSI));
                            shithappens = false;
                        } else if (issi.getText() != null && issi.getText().length() > 0
                                && LogicConstants.isNumeric(issi.getText())
                                && RecursoConsultas.alreadyExists(new Integer(issi.getText()))) {
                            shithappens = false;
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.dispositivoUnico"));
                        }
                    }
                    if (shithappens) {
                        if (name.getText().isEmpty()) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.nombreNulo"));
                        } else if (issi.getText() != null && issi.getText().length() > 0 && StringUtils
                                .trimToEmpty(issi.getText()).length() != LogicConstants.LONGITUD_ISSI) {
                            JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString(Locale.ROOT,
                                    "admin.recursos.popup.error.faltanCifras", LogicConstants.LONGITUD_ISSI));
                        } else if (issi.getText() != null && issi.getText().length() > 0
                                && LogicConstants.isNumeric(issi.getText()) && r != null && r.getId() != null
                                && RecursoConsultas.alreadyExists(new Integer(issi.getText()), r.getId())) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.issiUnico"));
                        } else if (issi.getText() != null && issi.getText().length() > 0
                                && !LogicConstants.isNumeric(issi.getText())) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.noNumerico"));
                            // } else if (identificador.getText().isEmpty())
                            // {
                            // JOptionPane
                            // .showMessageDialog(
                            // RecursoDialog.this,
                            // i18n.getString("admin.recursos.popup.error.identificadorNulo"));
                        } else if (subfleets.getSelectedIndex() == -1) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.noSubflota"));
                        } else if (types.getSelectedItem() == null
                                || types.getSelectedItem().toString().trim().isEmpty()) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.noTipo"));
                        } else {
                            int i = JOptionPane.showConfirmDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.dialogo.guardar.titulo"),
                                    i18n.getString("admin.recursos.popup.dialogo.guardar.guardar"),
                                    JOptionPane.YES_NO_CANCEL_OPTION);

                            if (i == JOptionPane.YES_OPTION) {

                                Recurso recurso = r;

                                if (r == null) {
                                    recurso = new Recurso();
                                }

                                recurso.setInfoAdicional(info.getText());
                                if (issi.getText() != null && issi.getText().length() > 0) {
                                    recurso.setDispositivo(new Integer(issi.getText()));
                                } else {
                                    recurso.setDispositivo(null);
                                }
                                recurso.setFlotas(FlotaConsultas.find(subfleets.getSelectedItem().toString()));
                                if (squads.getSelectedItem() != null && enabled.isSelected()) {
                                    recurso.setPatrullas(
                                            PatrullaConsultas.find(squads.getSelectedItem().toString()));
                                } else {
                                    recurso.setPatrullas(null);
                                }
                                recurso.setNombre(name.getText());
                                recurso.setHabilitado(enabled.isSelected());
                                // recurso.setIdentificador(identificador
                                // .getText());
                                recurso.setTipo(types.getSelectedItem().toString());
                                dispose();

                                RecursoAdmin.saveOrUpdate(recurso);
                                adminResources.refresh(null);

                                PluginEventHandler.fireChange(adminResources);
                            } else if (i == JOptionPane.NO_OPTION) {
                                dispose();
                            }
                        }
                    }
                } else {
                    log.debug("No hay cambios");
                    dispose();
                }

            } catch (Throwable t) {
                log.error("Error guardando un recurso", t);
            }
        }
    });
    buttons.add(accept);

    JButton cancelar = new JButton("Cancelar", LogicConstants.getIcon("button_cancel"));

    cancelar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (cambios) {
                if (JOptionPane.showConfirmDialog(RecursoDialog.this,
                        "Existen cambios sin guardar. Seguro que desea cerrar la ventana?",
                        "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION) != JOptionPane.CANCEL_OPTION) {
                    dispose();
                }
            } else {
                dispose();
            }
        }
    });

    buttons.add(cancelar);

    base.add(buttons);

    getContentPane().add(base);
    setLocationRelativeTo(null);
    cambios = false;
    if (r == null) {
        cambios = true;
    }

    pack();

    int x;
    int y;

    Container myParent = getBasicWindow().getPluginContainer().getDetachedTab(0);
    Point topLeft = myParent.getLocationOnScreen();
    Dimension parentSize = myParent.getSize();

    Dimension mySize = getSize();

    if (parentSize.width > mySize.width) {
        x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
    } else {
        x = topLeft.x;
    }

    if (parentSize.height > mySize.height) {
        y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
    } else {
        y = topLeft.y;
    }

    setLocation(x, y);
    cambios = false;
}

From source file:DialogDemo.java

/** Creates the panel shown by the second tab. */
private JPanel createFeatureDialogBox() {
    final int numButtons = 5;
    JRadioButton[] radioButtons = new JRadioButton[numButtons];
    final ButtonGroup group = new ButtonGroup();

    JButton showItButton = null;//from   ww  w . java 2 s  .  c o m

    final String pickOneCommand = "pickone";
    final String textEnteredCommand = "textfield";
    final String nonAutoCommand = "nonautooption";
    final String customOptionCommand = "customoption";
    final String nonModalCommand = "nonmodal";

    radioButtons[0] = new JRadioButton("Pick one of several choices");
    radioButtons[0].setActionCommand(pickOneCommand);

    radioButtons[1] = new JRadioButton("Enter some text");
    radioButtons[1].setActionCommand(textEnteredCommand);

    radioButtons[2] = new JRadioButton("Non-auto-closing dialog");
    radioButtons[2].setActionCommand(nonAutoCommand);

    radioButtons[3] = new JRadioButton("Input-validating dialog " + "(with custom message area)");
    radioButtons[3].setActionCommand(customOptionCommand);

    radioButtons[4] = new JRadioButton("Non-modal dialog");
    radioButtons[4].setActionCommand(nonModalCommand);

    for (int i = 0; i < numButtons; i++) {
        group.add(radioButtons[i]);
    }
    radioButtons[0].setSelected(true);

    showItButton = new JButton("Show it!");
    showItButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String command = group.getSelection().getActionCommand();

            // pick one of many
            if (command == pickOneCommand) {
                Object[] possibilities = { "ham", "spam", "yam" };
                String s = (String) JOptionPane.showInputDialog(frame,
                        "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog",
                        JOptionPane.PLAIN_MESSAGE, icon, possibilities, "ham");

                // If a string was returned, say so.
                if ((s != null) && (s.length() > 0)) {
                    setLabel("Green eggs and... " + s + "!");
                    return;
                }

                // If you're here, the return value was null/empty.
                setLabel("Come on, finish the sentence!");

                // text input
            } else if (command == textEnteredCommand) {
                String s = (String) JOptionPane.showInputDialog(frame,
                        "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog",
                        JOptionPane.PLAIN_MESSAGE, icon, null, "ham");

                // If a string was returned, say so.
                if ((s != null) && (s.length() > 0)) {
                    setLabel("Green eggs and... " + s + "!");
                    return;
                }

                // If you're here, the return value was null/empty.
                setLabel("Come on, finish the sentence!");

                // non-auto-closing dialog
            } else if (command == nonAutoCommand) {
                final JOptionPane optionPane = new JOptionPane(
                        "The only way to close this dialog is by\n" + "pressing one of the following buttons.\n"
                                + "Do you understand?",
                        JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);

                // You can't use pane.createDialog() because that
                // method sets up the JDialog with a property change
                // listener that automatically closes the window
                // when a button is clicked.
                final JDialog dialog = new JDialog(frame, "Click a button", true);
                dialog.setContentPane(optionPane);
                dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                dialog.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent we) {
                        setLabel("Thwarted user attempt to close window.");
                    }
                });
                optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent e) {
                        String prop = e.getPropertyName();

                        if (dialog.isVisible() && (e.getSource() == optionPane)
                                && (JOptionPane.VALUE_PROPERTY.equals(prop))) {
                            // If you were going to check something
                            // before closing the window, you'd do
                            // it here.
                            dialog.setVisible(false);
                        }
                    }
                });
                dialog.pack();
                dialog.setLocationRelativeTo(frame);
                dialog.setVisible(true);

                int value = ((Integer) optionPane.getValue()).intValue();
                if (value == JOptionPane.YES_OPTION) {
                    setLabel("Good.");
                } else if (value == JOptionPane.NO_OPTION) {
                    setLabel("Try using the window decorations " + "to close the non-auto-closing dialog. "
                            + "You can't!");
                } else {
                    setLabel("Window unavoidably closed (ESC?).");
                }

                // non-auto-closing dialog with custom message area
                // NOTE: if you don't intend to check the input,
                // then just use showInputDialog instead.
            } else if (command == customOptionCommand) {
                customDialog.setLocationRelativeTo(frame);
                customDialog.setVisible(true);

                String s = customDialog.getValidatedText();
                if (s != null) {
                    // The text is valid.
                    setLabel("Congratulations!  " + "You entered \"" + s + "\".");
                }

                // non-modal dialog
            } else if (command == nonModalCommand) {
                // Create the dialog.
                final JDialog dialog = new JDialog(frame, "A Non-Modal Dialog");

                // Add contents to it. It must have a close button,
                // since some L&Fs (notably Java/Metal) don't provide one
                // in the window decorations for dialogs.
                JLabel label = new JLabel("<html><p align=center>" + "This is a non-modal dialog.<br>"
                        + "You can have one or more of these up<br>" + "and still use the main window.");
                label.setHorizontalAlignment(JLabel.CENTER);
                Font font = label.getFont();
                label.setFont(label.getFont().deriveFont(font.PLAIN, 14.0f));

                JButton closeButton = new JButton("Close");
                closeButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        dialog.setVisible(false);
                        dialog.dispose();
                    }
                });
                JPanel closePanel = new JPanel();
                closePanel.setLayout(new BoxLayout(closePanel, BoxLayout.LINE_AXIS));
                closePanel.add(Box.createHorizontalGlue());
                closePanel.add(closeButton);
                closePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5));

                JPanel contentPane = new JPanel(new BorderLayout());
                contentPane.add(label, BorderLayout.CENTER);
                contentPane.add(closePanel, BorderLayout.PAGE_END);
                contentPane.setOpaque(true);
                dialog.setContentPane(contentPane);

                // Show it.
                dialog.setSize(new Dimension(300, 150));
                dialog.setLocationRelativeTo(frame);
                dialog.setVisible(true);
            }
        }
    });

    return createPane(moreDialogDesc + ":", radioButtons, showItButton);
}