Java Code Examples for javax.swing.text.JTextComponent#setEditable()

The following examples show how to use javax.swing.text.JTextComponent#setEditable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private static Box makeLeftIcon(JTextComponent label, ImageIcon icon) {
  label.setForeground(UIManager.getColor("Label.foreground"));
  // label.setBackground(UIManager.getColor("Label.background"));
  label.setOpaque(false);
  label.setEditable(false);
  label.setFocusable(false);
  label.setMaximumSize(label.getPreferredSize());
  label.setMinimumSize(label.getPreferredSize());

  JLabel l = new JLabel(icon);
  l.setCursor(Cursor.getDefaultCursor());
  Box box = Box.createHorizontalBox();
  box.add(l);
  box.add(Box.createHorizontalStrut(2));
  box.add(label);
  box.add(Box.createHorizontalGlue());
  return box;
}
 
Example 2
Source File: LookAndFeelTweaks.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public static void makeMultilineLabel(JTextComponent area) {
  area.setFont(UIManager.getFont("Label.font"));
  area.setEditable(false);
  area.setOpaque(false);    
  if (area instanceof JTextArea) {
    ((JTextArea)area).setWrapStyleWord(true);
    ((JTextArea)area).setLineWrap(true);
  }
}
 
Example 3
Source File: DesktopPickerField.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void setEditableToComponent(boolean editable) {
    for (Action action : actionsOrder) {
        if (action instanceof StandardAction) {
            ((StandardAction) action).setEditable(editable);
        }
    }
    if (!editable && impl.getEditor() instanceof JTextComponent) {
        JTextComponent editor = (JTextComponent) impl.getEditor();
        editor.setEditable(false);
    }
    updateMissingValueState();
}
 
Example 4
Source File: DialogEditor.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param textComp
 * @param editable
 */
public UnDoAbleDocument(JTextComponent textComp, boolean editable) {
    this(textComp);
    textComp.setEditable(editable);
    if (editable) {
        textComp.setBackground(ReduxConstants.myEditingWhiteColor);
    } else {
        textComp.setBackground(ReduxConstants.myNotEditingGreyColor);
    }

    textComp.addFocusListener(new SelectTextFocusListener());
}
 
Example 5
Source File: BaseSourcePanel.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
/**
   * Create the user interface.
   * The created {@link JTextComponent} depends on the {@link ISQLEntryPanelFactory}.
   * This enables support for Syntax-Highlighting, if the syntax plugin is loaded.
   */
  protected void createUserInterface()
  {
  	
  	HashMap<String, Object> props = new HashMap<String, Object>();
  	props.put(IParserEventsProcessorFactory.class.getName(), null);
  	
ISQLEntryPanel sqlPanel = getSession().getApplication().getSQLEntryPanelFactory().createSQLEntryPanel(getSession(), props );
JTextComponent textComponent = sqlPanel.getTextComponent();
textComponent.setEditable(false);
setTextArea(textComponent);
add(getTextArea(), BorderLayout.CENTER);
  }
 
Example 6
Source File: LookAndFeelTweaks.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public static void makeMultilineLabel(JTextComponent area) {
  area.setFont(UIManager.getFont("Label.font"));
  area.setEditable(false);
  area.setOpaque(false);
  if (area instanceof JTextArea) {
    ((JTextArea) area).setWrapStyleWord(true);
    ((JTextArea) area).setLineWrap(true);
  }
}
 
Example 7
Source File: PromptDialog.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static JComponent addComponent(final JPanel content, final GridBagConstraints gbc,
                                       final String label, final String defaultValue, final TYPE type) {
    if (type.equals(TYPE.CHECKBOX)) {
        final JCheckBox checkBox = new JCheckBox(label);
        checkBox.setSelected(!defaultValue.isEmpty());
        content.add(checkBox, gbc);
        return checkBox;
    }
    JTextComponent textComp;
    if (type.equals(TYPE.TEXTAREA)) {
        final JTextArea textArea = new JTextArea(defaultValue);
        textArea.setColumns(50);
        textArea.setRows(7);
        textComp = textArea;
    } else {
        gbc.gridx = 0;
        content.add(new JLabel(label), gbc);
        gbc.weightx = 2;
        gbc.gridx = 1;
        if (type.equals(TYPE.PASSWORD)) {
            textComp = new  JPasswordField(defaultValue);
            ((JPasswordField)textComp).setEchoChar('*');
        } else {
            textComp = new JTextField(defaultValue);
        }
        gbc.weightx = 1;
    }
    textComp.setEditable(true);
    content.add(textComp, gbc);
    gbc.gridx = 0;
    return textComp;
}
 
Example 8
Source File: LookAndFeelTweaks.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public static void makeMultilineLabel(JTextComponent area) {
    area.setFont(UIManager.getFont("Label.font"));
    area.setEditable(false);
    area.setOpaque(false);
    if (area instanceof JTextArea) {
        ((JTextArea) area).setWrapStyleWord(true);
        ((JTextArea) area).setLineWrap(true);
    }
}
 
Example 9
Source File: InPlaceEditLayer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
void setEditedComponent(Component comp, String text) {
    if (!comp.isShowing() || comp.getParent() == null)
        throw new IllegalArgumentException();

    editedComp = comp;
    editedText = text;
    if (inPlaceField != null) {
        remove(inPlaceField);
        inPlaceField = null;
    }

    if (comp instanceof JLabel || comp instanceof AbstractButton || comp instanceof JTabbedPane) {
        layerEditing = true;
        superContainer = null;
        createInPlaceField();
    }
    else if (comp instanceof JTextField || comp instanceof JTextArea) {
        layerEditing = false;
        superContainer = comp.getParent();

        Container cont = superContainer;
        do {
            if (cont.getParent() instanceof JLayeredPane) {
                superContainer = cont;
                break;
            }
            else cont = cont.getParent();
        }
        while (cont != null);

        editingTextComp = (JTextComponent)editedComp;
        oldText = editingTextComp.getText();
        editingTextComp.setText(editedText);

        // enable focus on component in component layer
        editingTextComp.setFocusable(true);
        if (!editingTextComp.isEnabled()) {
            editingTextComp.setEnabled(true);
            enabled = true;
        }
        if (!editingTextComp.isEditable()) {
            editingTextComp.setEditable(true);
            madeEditable = true;
        }
    }
    else throw new IllegalArgumentException();

    if (editingTextComp != null) {
        FormUtils.setupTextUndoRedo(editingTextComp);
    }

    attachListeners();
}
 
Example 10
Source File: MessageConsole.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
public MessageConsole(JTextComponent textComponent, boolean isAppend) {
    this.textComponent = textComponent;
    this.document = textComponent.getDocument();
    this.isAppend = isAppend;
    textComponent.setEditable(false);
}
 
Example 11
Source File: MessageConsole.java    From portable-ftp-server with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Instantiates a new message console.
 *
 * @param textComponent the text component
 */
public MessageConsole(JTextComponent textComponent){
	this.textComponent = textComponent;
	this.document = textComponent.getDocument();
	textComponent.setEditable(false);
}
 
Example 12
Source File: MessageConsole.java    From eml-to-pdf-converter with Apache License 2.0 4 votes vote down vote up
public MessageConsole(JTextComponent textComponent, boolean isAppend) {
	this.textComponent = textComponent;
	this.document = textComponent.getDocument();
	this.isAppend = isAppend;
	textComponent.setEditable(false);
}
 
Example 13
Source File: FrameUtil.java    From yawl with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void readOnly(JTextComponent c, JComponent parent) {
  c.setEditable(false);
  c.setForeground(parent.getForeground());
  c.setBackground(parent.getBackground());
}
 
Example 14
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());
  String[] columnNames = {"String", "Integer", "Boolean"};
  Object[][] data = {
    {"aaa", 12, true}, {"zzz", 6, false}, {"bbb", 22, true}, {"nnn", 9, false},
    {"ccc", 32, true}, {"ooo", 8, false}, {"ddd", 42, true}, {"ppp", 9, false},
    {"eee", 52, true}, {"qqq", 8, false}, {"fff", 62, true}, {"rrr", 7, false},
    {"ggg", 51, true}, {"sss", 6, false}, {"hhh", 41, true}, {"ttt", 5, false},
    {"iii", 51, true}, {"uuu", 4, false}, {"jjj", 61, true}, {"vvv", 3, false},
    {"kkk", 72, true}, {"www", 2, false}, {"lll", 82, true}, {"xxx", 1, false},
    {"mmm", 92, true}, {"yyy", 0, false}
  };
  DefaultTableModel model = new DefaultTableModel(data, columnNames) {
    @Override public Class<?> getColumnClass(int column) {
      return getValueAt(0, column).getClass();
    }
  };
  JTable table = new JTable(model);
  table.setAutoCreateRowSorter(true);

  JTextPane textPane = new JTextPane();
  textPane.setEditable(false);
  textPane.setMargin(new Insets(5, 10, 5, 5));

  JTextComponent c = new JTextArea(TEXT);
  c.setEditable(false);

  Document doc = textPane.getDocument();
  try {
    doc.insertString(doc.getLength(), TEXT, null);
    doc.insertString(doc.getLength(), TEXT, null);
    doc.insertString(doc.getLength(), TEXT, null);
    textPane.insertComponent(createChildScrollPane(c));
    doc.insertString(doc.getLength(), "\n", null);
    doc.insertString(doc.getLength(), TEXT, null);
    textPane.insertComponent(createChildScrollPane(table));
    doc.insertString(doc.getLength(), "\n", null);
    doc.insertString(doc.getLength(), TEXT, null);
    textPane.insertComponent(new JScrollPane(new JTree()));
    doc.insertString(doc.getLength(), "\n", null);
    doc.insertString(doc.getLength(), TEXT, null);
  } catch (BadLocationException ex) {
    // should never happen
    RuntimeException wrap = new StringIndexOutOfBoundsException(ex.offsetRequested());
    wrap.initCause(ex);
    throw wrap;
  }
  add(new JLayer<>(new JScrollPane(textPane), new WheelScrollLayerUI()));
  // add(new JScrollPane(textPane));
  setPreferredSize(new Dimension(320, 240));
}