List of usage examples for javax.swing JTextField setEditable
@BeanProperty(description = "specifies if the text can be edited") public void setEditable(boolean b)
TextComponent
should be editable. From source file:CaretSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Caret Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); content.add(scrollPane, BorderLayout.CENTER); final JTextField dot = new JTextField(); dot.setEditable(false); JPanel dotPanel = new JPanel(new BorderLayout()); dotPanel.add(new JLabel("Dot: "), BorderLayout.WEST); dotPanel.add(dot, BorderLayout.CENTER); content.add(dotPanel, BorderLayout.NORTH); final JTextField mark = new JTextField(); mark.setEditable(false);/*from ww w . ja va2 s . c o m*/ JPanel markPanel = new JPanel(new BorderLayout()); markPanel.add(new JLabel("Mark: "), BorderLayout.WEST); markPanel.add(mark, BorderLayout.CENTER); content.add(markPanel, BorderLayout.SOUTH); CaretListener listener = new CaretListener() { public void caretUpdate(CaretEvent caretEvent) { dot.setText("" + caretEvent.getDot()); mark.setText("" + caretEvent.getMark()); } }; textArea.addCaretListener(listener); frame.setSize(250, 150); frame.setVisible(true); }
From source file:EditabilityExample.java
public static void main(String[] args) { try {/* www .jav a 2 s . co m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Editability Example"); f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS)); f.getContentPane().add(firstField); JTextField tf = new JTextField("A read-only text field", 20); tf.setEditable(false); f.getContentPane().add(tf); JTextArea ta = new JTextArea("An editable\ntext area", 2, 20); ta.setBorder(BorderFactory.createLoweredBevelBorder()); f.getContentPane().add(ta); ta = new JTextArea("A read-only\ntext area", 2, 20); ta.setBorder(BorderFactory.createLoweredBevelBorder()); ta.setEditable(false); f.getContentPane().add(ta); f.pack(); f.show(); if (args.length == 1 && args[0].equals("disable")) { // Toggle the enabled state of the first // text field every 10 seconds Timer t = new Timer(10000, new ActionListener() { public void actionPerformed(ActionEvent evt) { firstField.setEnabled(!firstField.isEnabled()); firstField.setText(firstFieldText + (firstField.isEnabled() ? "" : " (disabled)")); } }); t.start(); } }
From source file:Main.java
public static void setEnabled(JTextField textField, boolean b) { textField.setEditable(b); textField.setEnabled(b);/*from w ww . j a va 2 s . c om*/ }
From source file:TrackEvent.java
public void init() { Container c = getContentPane(); c.setLayout(new GridLayout(event.length + 1, 2)); for (int i = 0; i < event.length; i++) { JTextField t = new JTextField(); t.setEditable(false); c.add(new JLabel(event[i], JLabel.RIGHT)); c.add(t);/*from w w w. j a v a2 s . co m*/ h.put(event[i], t); } c.add(b1); c.add(b2); }
From source file:Flipper.java
private JTextField makeText() { JTextField t = new JTextField(20); t.setEditable(false); t.setHorizontalAlignment(JTextField.RIGHT); t.setBorder(border);/* w w w .j a va2s . co m*/ getContentPane().add(t, constraints); return t; }
From source file:biomine.bmvis2.pipeline.EdgeGoodnessHider.java
public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { double maxEdge = 0; for (VisualEdge e : graph.getAllEdges()) { maxEdge = Math.max(maxEdge, e.getGoodness()); }/* w ww . j ava 2s .c o m*/ final int scale = 100; final JSlider limitSlider = new JSlider(); limitSlider.setMinimum(0); limitSlider.setMaximum(scale); limitSlider.setValue((int) (limit * scale)); final JTextField limitText = new JTextField(); limitText.setEditable(false); limitText.setText("" + limit); limitSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { limit = limitSlider.getValue() / (double) scale; limitText.setText("" + limit); v.settingsChanged(false); } }); JPanel ret = new JPanel(); GridBagLayout bag = new GridBagLayout(); ret.setLayout(bag); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = c.HORIZONTAL; ret.add(limitSlider, c); c.gridy++; ret.add(limitText, c); return ret; }
From source file:DecimalFormatDemo.java
public DecimalFormatDemo() { availableLocales = new LocaleGroup(); inputFormatter = NumberFormat.getNumberInstance(); String[] patternExamples = { "##.##", "###,###.##", "##,##,##.##", "#", "000,000.0000", "##.0000", "'hello'###.##" }; currentPattern = patternExamples[0]; // Set up the UI for entering a number. JLabel numberLabel = new JLabel("Enter the number to format:"); numberLabel.setAlignmentX(Component.LEFT_ALIGNMENT); JTextField numberField = new JTextField(); numberField.setEditable(true); numberField.setAlignmentX(Component.LEFT_ALIGNMENT); NumberListener numberListener = new NumberListener(); numberField.addActionListener(numberListener); // Set up the UI for selecting a pattern. JLabel patternLabel1 = new JLabel("Enter the pattern string or"); JLabel patternLabel2 = new JLabel("select one from the list:"); patternLabel1.setAlignmentX(Component.LEFT_ALIGNMENT); patternLabel2.setAlignmentX(Component.LEFT_ALIGNMENT); JComboBox patternList = new JComboBox(patternExamples); patternList.setSelectedIndex(0);//from w w w . j av a2s .c om patternList.setEditable(true); patternList.setAlignmentX(Component.LEFT_ALIGNMENT); PatternListener patternListener = new PatternListener(); patternList.addActionListener(patternListener); // Set up the UI for selecting a locale. JLabel localeLabel = new JLabel("Select a Locale from the list:"); localeLabel.setAlignmentX(Component.LEFT_ALIGNMENT); JComboBox localeList = new JComboBox(availableLocales.getStrings()); localeList.setSelectedIndex(0); localeList.setAlignmentX(Component.LEFT_ALIGNMENT); LocaleListener localeListener = new LocaleListener(); localeList.addActionListener(localeListener); // Create the UI for displaying result. JLabel resultLabel = new JLabel("Result", JLabel.LEFT); resultLabel.setAlignmentX(Component.LEFT_ALIGNMENT); result = new JLabel(" "); result.setForeground(Color.black); result.setAlignmentX(Component.LEFT_ALIGNMENT); result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black), BorderFactory.createEmptyBorder(5, 5, 5, 5))); // Lay out everything JPanel numberPanel = new JPanel(); numberPanel.setLayout(new GridLayout(0, 1)); numberPanel.add(numberLabel); numberPanel.add(numberField); JPanel patternPanel = new JPanel(); patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.Y_AXIS)); patternPanel.add(patternLabel1); patternPanel.add(patternLabel2); patternPanel.add(patternList); JPanel localePanel = new JPanel(); localePanel.setLayout(new BoxLayout(localePanel, BoxLayout.Y_AXIS)); localePanel.add(localeLabel); localePanel.add(localeList); JPanel resultPanel = new JPanel(); resultPanel.setLayout(new GridLayout(0, 1)); resultPanel.add(resultLabel); resultPanel.add(result); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); patternPanel.setAlignmentX(Component.CENTER_ALIGNMENT); numberPanel.setAlignmentX(Component.CENTER_ALIGNMENT); localePanel.setAlignmentX(Component.CENTER_ALIGNMENT); resultPanel.setAlignmentX(Component.CENTER_ALIGNMENT); add(numberPanel); add(Box.createVerticalStrut(10)); add(patternPanel); add(Box.createVerticalStrut(10)); add(localePanel); add(Box.createVerticalStrut(10)); add(resultPanel); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); reformat(); numberField.setText(result.getText()); }
From source file:org.gumtree.vis.awt.AbstractPlotEditor.java
private JPanel createHelpPanel() { JPanel wrap = new JPanel(new GridLayout(1, 1)); JPanel helpPanel = new JPanel(new GridLayout(1, 1)); helpPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); // helpPanel.setBorder(BorderFactory.createTitledBorder( // BorderFactory.createEtchedBorder(), "Help Topics")); SpringLayout spring = new SpringLayout(); JPanel inner = new JPanel(spring); inner.setBorder(BorderFactory.createEmptyBorder()); final IHelpProvider provider = plot.getHelpProvider(); final JList list = new JList(provider.getHelpMap().keySet().toArray()); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // list.setBorder(BorderFactory.createEtchedBorder()); JScrollPane listPane1 = new JScrollPane(list); inner.add(listPane1);/*from w ww . j a va 2 s. c om*/ listPane1.setMaximumSize(new Dimension(140, 0)); listPane1.setMinimumSize(new Dimension(70, 0)); // JPanel contentPanel = new JPanel(new GridLayout(2, 1)); // inner.add(list); final JTextField keyField = new JTextField(); keyField.setMaximumSize(new Dimension(400, 20)); keyField.setEditable(false); // keyField.setMaximumSize(); // keyArea.setLineWrap(true); // keyArea.setWrapStyleWord(true); // keyArea.setBorder(BorderFactory.createEtchedBorder()); inner.add(keyField); // contentPanel.add(new JLabel()); // contentPanel.add(new JLabel()); final JTextArea helpArea = new JTextArea(); JScrollPane areaPane = new JScrollPane(helpArea); helpArea.setEditable(false); helpArea.setLineWrap(true); helpArea.setWrapStyleWord(true); // helpArea.setBorder(BorderFactory.createEtchedBorder()); inner.add(areaPane); // contentPanel.add(new JLabel()); // contentPanel.add(new JLabel()); // inner.add(contentPanel); spring.putConstraint(SpringLayout.WEST, listPane1, 2, SpringLayout.WEST, inner); spring.putConstraint(SpringLayout.NORTH, listPane1, 2, SpringLayout.NORTH, inner); spring.putConstraint(SpringLayout.WEST, keyField, 4, SpringLayout.EAST, listPane1); spring.putConstraint(SpringLayout.NORTH, keyField, 2, SpringLayout.NORTH, inner); spring.putConstraint(SpringLayout.EAST, inner, 2, SpringLayout.EAST, keyField); spring.putConstraint(SpringLayout.WEST, areaPane, 4, SpringLayout.EAST, listPane1); spring.putConstraint(SpringLayout.NORTH, areaPane, 4, SpringLayout.SOUTH, keyField); spring.putConstraint(SpringLayout.EAST, areaPane, -2, SpringLayout.EAST, inner); spring.putConstraint(SpringLayout.SOUTH, inner, 2, SpringLayout.SOUTH, areaPane); spring.putConstraint(SpringLayout.SOUTH, listPane1, -2, SpringLayout.SOUTH, inner); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { Object[] selected = list.getSelectedValues(); if (selected.length >= 0) { HelpObject help = provider.getHelpMap().get(selected[0]); if (help != null) { keyField.setText(help.getKey()); helpArea.setText(help.getDiscription()); } } } }); helpPanel.add(inner, BorderLayout.NORTH); wrap.setName("Help"); wrap.add(helpPanel, BorderLayout.NORTH); return wrap; }
From source file:es.emergya.ui.gis.popups.GenericDialog.java
protected void addString_Fixed(String texto, String label) { rows++;//w w w .ja v a2s . c o m mid.add(new JLabel(i18n.getString(label), JLabel.RIGHT)); JTextField jtextField = new JTextField(texto); jtextField.setEditable(false); 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 addString(String texto, String label) { rows++;/*from w w w . j ava 2s . c om*/ mid.add(new JLabel(i18n.getString(label), JLabel.RIGHT)); JTextField jtextField = new JTextField(texto); jtextField.setEditable(true); jtextField.setName(label); mid.add(jtextField); componentes.add(jtextField); for (int i = 2; i < cols; i++) mid.add(Box.createHorizontalGlue()); }