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

The following examples show how to use javax.swing.text.JTextComponent#setFocusable() . 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: DesktopPickerField.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void updateEnabled() {
    super.updateEnabled();

    boolean resultEnabled = isEnabledWithParent();
    for (DesktopButton button : buttons) {
        button.setParentEnabled(resultEnabled);
    }

    if (impl.getEditor() instanceof JTextComponent) {
        JTextComponent editor = (JTextComponent) impl.getEditor();
        editor.setFocusable(resultEnabled);
    }
}
 
Example 3
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();
}