Example usage for javax.swing JTextField setEditable

List of usage examples for javax.swing JTextField setEditable

Introduction

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

Prototype

@BeanProperty(description = "specifies if the text can be edited")
public void setEditable(boolean b) 

Source Link

Document

Sets the specified boolean to indicate whether or not this TextComponent should be editable.

Usage

From source file:es.emergya.ui.plugins.forms.FormGeneric.java

protected void addString(String texto, String label) {
    rows++;//  w w w. j  a v a  2s .  c  o  m
    mid.add(new JLabel(i18n.getString(label), JLabel.RIGHT));
    JTextField jtextField = new JTextField(texto);
    jtextField.setName(label);
    jtextField.setEditable(true);
    componentes.add(jtextField);
    mid.add(jtextField);
    for (int i = 2; i < cols; i++)
        mid.add(Box.createHorizontalGlue());
}

From source file:es.emergya.ui.gis.popups.GenericDialog.java

protected void addRow(String[][] pairs) {
    rows++;// ww w  .ja  v  a  2  s .  c  o  m
    if (pairs.length > cols)
        log.error("Se va a descuadrar");

    int columnas = 0;
    for (String[] pair : pairs) {
        if (pair.length != 2)
            log.error("Par desconocido");
        else {
            columnas += 2;
            mid.add(new JLabel(i18n.getString(pair[0]), JLabel.RIGHT));
            JTextField jtextField = new JTextField(pair[1]);
            jtextField.setEditable(true);
            mid.add(jtextField);
        }
    }
    while (columnas < cols) {
        mid.add(Box.createHorizontalGlue());
        columnas++;
    }
}

From source file:edu.clemson.cs.nestbed.client.gui.MessageMonitorFrame.java

private JPanel buildFieldPanel(List<Method> methodList) {
    JPanel panel = new JPanel();
    int rows = methodList.size();
    int cols = 1;

    panel.setLayout(new GridLayout(rows, cols));

    for (Method i : methodList) {
        JTextField textField = new JTextField();
        textField.setEditable(false);

        methodFieldMap.put(i, textField);
        panel.add(textField);//from ww w  .java2  s. c o m
    }

    return panel;
}

From source file:es.emergya.ui.gis.popups.GenericDialog.java

protected void addJoinedRow(String[][] pairs, Integer[] colsLength) {
    if (pairs == null || pairs.length == 0 || pairs.length != colsLength.length)
        return;//  www  .j  a va 2s.co m
    rows++;

    int contador = 0;
    for (int i : colsLength)
        contador += i;
    final FlowLayout flowLayout = new FlowLayout();
    JPanel panel = new JPanel(flowLayout);
    panel.setOpaque(false);
    JTextField jtextField = new JTextField(pairs[0][1]);
    jtextField.setEditable(true);
    jtextField.setColumns(colsLength[0]);
    panel.add(jtextField);
    mid.add(new JLabel(i18n.getString(pairs[0][0]), JLabel.RIGHT));

    for (int i = 1; i < pairs.length; i++) {
        String[] pair = pairs[i];
        if (pair.length != 2)
            log.error("Par desconocido");
        else {
            panel.add(new JLabel(i18n.getString(pair[0]), JLabel.RIGHT));
            jtextField = new JTextField(pair[1]);
            jtextField.setEditable(true);
            panel.add(jtextField);
            jtextField.setColumns(colsLength[i]);
        }
    }
    if (contador < 100)
        for (int i = contador; i < 100; i += 5)
            panel.add(new JLabel("        "));

    mid.add(panel);

    for (int i = 2; i < cols; i++)
        mid.add(Box.createHorizontalGlue());
}

From source file:LDAPTest.java

/**
     * Constructs the data panel.//from   w w  w .ja  va 2  s . co m
     * @param attributes the attributes of the given entry
     */
    public DataPanel(Attributes attrs) throws NamingException {
        setLayout(new java.awt.GridLayout(0, 2, 3, 1));

        NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll();
        while (attrEnum.hasMore()) {
            Attribute attr = attrEnum.next();
            String id = attr.getID();

            NamingEnumeration<?> valueEnum = attr.getAll();
            while (valueEnum.hasMore()) {
                Object value = valueEnum.next();
                if (id.equals("userPassword"))
                    value = new String((byte[]) value);

                JLabel idLabel = new JLabel(id, SwingConstants.RIGHT);
                JTextField valueField = new JTextField("" + value);
                if (id.equals("objectClass"))
                    valueField.setEditable(false);
                if (!id.equals("uid")) {
                    add(idLabel);
                    add(valueField);
                }
            }
        }
    }

From source file:DesktopAppTest.java

public DesktopAppFrame() {
    setLayout(new GridBagLayout());
    final JFileChooser chooser = new JFileChooser();
    JButton fileChooserButton = new JButton("...");
    final JTextField fileField = new JTextField(20);
    fileField.setEditable(false);
    JButton openButton = new JButton("Open");
    JButton editButton = new JButton("Edit");
    JButton printButton = new JButton("Print");
    final JTextField browseField = new JTextField();
    JButton browseButton = new JButton("Browse");
    final JTextField toField = new JTextField();
    final JTextField subjectField = new JTextField();
    JButton mailButton = new JButton("Mail");

    openButton.setEnabled(false);//w  ww  .j av a  2 s  .  c o m
    editButton.setEnabled(false);
    printButton.setEnabled(false);
    browseButton.setEnabled(false);
    mailButton.setEnabled(false);

    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.OPEN))
            openButton.setEnabled(true);
        if (desktop.isSupported(Desktop.Action.EDIT))
            editButton.setEnabled(true);
        if (desktop.isSupported(Desktop.Action.PRINT))
            printButton.setEnabled(true);
        if (desktop.isSupported(Desktop.Action.BROWSE))
            browseButton.setEnabled(true);
        if (desktop.isSupported(Desktop.Action.MAIL))
            mailButton.setEnabled(true);
    }

    fileChooserButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (chooser.showOpenDialog(DesktopAppFrame.this) == JFileChooser.APPROVE_OPTION)
                fileField.setText(chooser.getSelectedFile().getAbsolutePath());
        }
    });

    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().open(chooser.getSelectedFile());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });

    editButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().edit(chooser.getSelectedFile());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });

    printButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().print(chooser.getSelectedFile());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });

    browseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().browse(new URI(browseField.getText()));
            } catch (URISyntaxException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });

    mailButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                String subject = percentEncode(subjectField.getText());
                URI uri = new URI("mailto:" + toField.getText() + "?subject=" + subject);

                System.out.println(uri);
                Desktop.getDesktop().mail(uri);
            } catch (URISyntaxException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });

    JPanel buttonPanel = new JPanel();
    ((FlowLayout) buttonPanel.getLayout()).setHgap(2);
    buttonPanel.add(openButton);
    buttonPanel.add(editButton);
    buttonPanel.add(printButton);

    add(fileChooserButton, new GBC(0, 0).setAnchor(GBC.EAST).setInsets(2));
    add(fileField, new GBC(1, 0).setFill(GBC.HORIZONTAL));
    add(buttonPanel, new GBC(2, 0).setAnchor(GBC.WEST).setInsets(0));
    add(browseField, new GBC(1, 1).setFill(GBC.HORIZONTAL));
    add(browseButton, new GBC(2, 1).setAnchor(GBC.WEST).setInsets(2));
    add(new JLabel("To:"), new GBC(0, 2).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2));
    add(toField, new GBC(1, 2).setFill(GBC.HORIZONTAL));
    add(mailButton, new GBC(2, 2).setAnchor(GBC.WEST).setInsets(2));
    add(new JLabel("Subject:"), new GBC(0, 3).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2));
    add(subjectField, new GBC(1, 3).setFill(GBC.HORIZONTAL));

    pack();
}

From source file:ViewDB.java

 /**
 * Constructs the data panel.// w  w w.ja  v a  2 s . co  m
 * @param rs the result set whose contents this panel displays
 */
public DataPanel(RowSet rs) throws SQLException
{
   fields = new ArrayList<JTextField>();
   setLayout(new GridBagLayout());
   GridBagConstraints gbc = new GridBagConstraints();
   gbc.gridwidth = 1;
   gbc.gridheight = 1;

   ResultSetMetaData rsmd = rs.getMetaData();
   for (int i = 1; i <= rsmd.getColumnCount(); i++)
   {
      gbc.gridy = i - 1;

      String columnName = rsmd.getColumnLabel(i);
      gbc.gridx = 0;
      gbc.anchor = GridBagConstraints.EAST;
      add(new JLabel(columnName), gbc);

      int columnWidth = rsmd.getColumnDisplaySize(i);
      JTextField tb = new JTextField(columnWidth);
      if (!rsmd.getColumnClassName(i).equals("java.lang.String"))
         tb.setEditable(false);
               
      fields.add(tb);

      gbc.gridx = 1;
      gbc.anchor = GridBagConstraints.WEST;
      add(tb, gbc);
   }
}

From source file:es.emergya.ui.gis.popups.SaveGPXDialog.java

private SaveGPXDialog(final List<Layer> capas) {
    super("Consulta de Posiciones GPS");
    setResizable(false);//from w  w w.  j a v  a2 s.  c  o  m
    setAlwaysOnTop(true);
    try {
        setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getIconImage());
    } catch (Throwable e) {
        LOG.error("There is no icon image", e);
    }

    this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    JPanel dialogo = new JPanel(new BorderLayout());
    dialogo.setBackground(Color.WHITE);
    dialogo.setBorder(new EmptyBorder(10, 10, 10, 10));

    JPanel central = new JPanel(new FlowLayout());
    central.setOpaque(false);
    final JTextField nombre = new JTextField(15);
    nombre.setEditable(false);
    central.add(nombre);
    final JButton button = new JButton("Examinar...", LogicConstants.getIcon("button_nuevo"));
    central.add(button);
    final JButton aceptar = new JButton("Guardar", LogicConstants.getIcon("button_save"));
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            if (fileChooser.showSaveDialog(SaveGPXDialog.this) == JFileChooser.APPROVE_OPTION) {
                nombre.setText(fileChooser.getSelectedFile().getAbsolutePath());
                aceptar.setEnabled(true);
            }
        }
    });

    dialogo.add(central, BorderLayout.CENTER);

    JPanel botones = new JPanel(new FlowLayout());
    botones.setOpaque(false);

    aceptar.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String base_url = nombre.getText() + "_";
            for (Layer layer : capas) {
                if (layer instanceof GpxLayer) {
                    GpxLayer gpxLayer = (GpxLayer) layer;
                    File f = new File(base_url + gpxLayer.name + ".gpx");

                    boolean sobreescribir = !f.exists();

                    try {
                        while (!sobreescribir) {
                            String original = f.getCanonicalPath();
                            f = checkFileOverwritten(nombre, f);
                            sobreescribir = !f.exists() || original.equals(f.getCanonicalPath());
                        }
                    } catch (NullPointerException t) {
                        log.debug("Cancelando creacion de fichero: " + t);
                        sobreescribir = false;
                    } catch (Throwable t) {
                        log.error("Error comprobando la sobreescritura", t);
                        sobreescribir = false;
                    }

                    if (sobreescribir) {
                        try {
                            f.createNewFile();
                        } catch (IOException e1) {
                            log.error(e1, e1);
                        }
                        if (!(f.isFile() && f.canWrite()))
                            JOptionPane.showMessageDialog(SaveGPXDialog.this,
                                    "No tengo permiso para escribir en " + f.getAbsolutePath());
                        else {
                            try {
                                OutputStream out = new FileOutputStream(f);
                                GpxWriter writer = new GpxWriter(out);
                                writer.write(gpxLayer.data);
                                out.close();
                            } catch (Throwable t) {
                                log.error("Error al escribir el gpx", t);
                                JOptionPane.showMessageDialog(SaveGPXDialog.this,
                                        "Ocurri un error al escribir en " + f.getAbsolutePath());
                            }
                        }
                    } else
                        log.error("Por errores anteriores no se escribio el fichero");
                } else
                    log.error("Una de las capas no era gpx: " + layer.name);
            }
            SaveGPXDialog.this.dispose();

        }

        private File checkFileOverwritten(final JTextField nombre, File f) throws Exception {
            String nueva = JOptionPane.showInputDialog(nombre, i18n.getString("savegpxdialog.overwrite"),
                    "Sobreescribir archivo", JOptionPane.QUESTION_MESSAGE, null, null, f.getCanonicalPath())
                    .toString();
            log.debug("Nueva ruta: " + nueva);
            return new File(nueva);
        }
    });

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

    cancelar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SaveGPXDialog.this.dispose();
        }
    });

    aceptar.setEnabled(false);
    botones.add(aceptar);
    botones.add(cancelar);
    dialogo.add(botones, BorderLayout.SOUTH);

    add(dialogo);
    setPreferredSize(new Dimension(300, 200));
    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 windowClosed(WindowEvent e) {
            nombre.setText("");
            nombre.repaint();
        }

        @Override
        public void windowClosing(WindowEvent e) {
            nombre.setText("");
            nombre.repaint();
        }
    });
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.SGRResultsForForm.java

public void refresh() {
    if (currentIndex < 0)
        return;//from w w w . j  av a  2  s . c om

    removeAll();
    repaint();

    if (!sgrPlugin.isReady()) {
        showMessage("SGR_NO_MATCHER");
        return;
    }

    setCursor(new Cursor(Cursor.WAIT_CURSOR));
    new SwingWorker<MatchResults, Void>() {
        private int index = currentIndex;

        @Override
        protected MatchResults doInBackground() throws Exception {
            int modelIndex = workbenchPaneSS.getSpreadSheet().convertRowIndexToModel(index);
            WorkbenchRow row = workbench.getRow(modelIndex);
            return isEmpty(row) ? null : sgrPlugin.doQuery(row);
        }

        @Override
        protected void done() {
            // if we changed indexes in the meantime, don't show this result.
            if (index != currentIndex)
                return;
            //removeAll();

            try {
                results = get();
            } catch (CancellationException e) {
                return;
            } catch (InterruptedException e) {
                return;
            } catch (ExecutionException e) {
                sgrFailed(e);
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            if (results == null || results.matches.size() < 1) {
                showMessage("SGR_NO_RESULTS");
                return;
            }

            float maxScore = sgrPlugin.getColorizer().getMaxScore();
            if (maxScore == 0.0f)
                maxScore = 22.0f;

            StringBuilder columns = new StringBuilder("right:max(50dlu;p)");
            for (Match result : results) {
                columns.append(", 4dlu, 150dlu:grow");
            }

            String[] fields = columnOrdering.getFields();
            StringBuilder rows = new StringBuilder();
            for (int i = 0; i < fields.length - 1; i++) {
                rows.append("p, 4dlu,");
            }
            rows.append("p");

            FormLayout layout = new FormLayout(columns.toString(), rows.toString());
            PanelBuilder builder = new PanelBuilder(layout, SGRResultsForForm.this);
            CellConstraints cc = new CellConstraints();

            int y = 1;
            for (String heading : columnOrdering.getHeadings()) {
                builder.addLabel(heading + ":", cc.xy(1, y));
                y += 2;
            }

            int x = 3;
            for (Match result : results) {
                y = 1;
                for (String field : fields) {
                    String value;
                    Color color;
                    if (field.equals("id")) {
                        value = result.match.id;
                        color = SGRColors.colorForScore(result.score, maxScore);
                    } else if (field.equals("score")) {
                        value = String.format("%1$.2f", result.score);
                        color = SGRColors.colorForScore(result.score, maxScore);
                    } else {
                        value = StringUtils.join(result.match.getFieldValues(field).toArray(), "; ");
                        Float fieldContribution = result.fieldScoreContributions().get(field);
                        color = SGRColors.colorForScore(result.score, maxScore, fieldContribution);
                    }

                    JTextField textField = new JTextField(value);
                    textField.setBackground(color);
                    textField.setEditable(false);
                    textField.setCaretPosition(0);
                    builder.add(textField, cc.xy(x, y));
                    y += 2;
                }
                x += 2;
            }
            getParent().validate();
        }
    }.execute();
    UsageTracker.incrUsageCount("SGR.MatchRow");
}

From source file:com.google.cloud.tools.intellij.appengine.cloud.AppEngineDeploymentRunConfigurationEditor.java

private void resetOverridableFields(JCheckBox overrideCheckbox, JTextField field) {
    field.setEditable(overrideCheckbox.isSelected());
}