Disable « JTextField « Java Swing Q&A





1. Text Field disabling in NetBeans    stackoverflow.com

I want to ask if there is a way to make the text field active and inactive according to the radio button. For example, the textfield will be inactive and when the ...

2. How to disable default textfield shortcuts in JTextField    stackoverflow.com

I have a custom textfield class that extends the JTextField class in Swing. I need to find a way to disable the default actions for Ctrl-A (select all), Ctrl-H (backspace) etc, so ...

3. Disable input some symbols to JTextField    stackoverflow.com

How can I disable input of any symbol except digits to JTextField?

4. disable keyboard for Textfield    coderanch.com

Hi Vinod, There is two ways you can choose from: (1) yourTextField.setEditable( false ); Sets the specified boolean to indicate whether or not this TextComponent should be editable. A PropertyChange event ("editable") is fired when the state is changed. (2) yourTextField.setEnabled( false ); Sets whether or not this component is enabled. A component that is enabled may respond to user input, ...

7. Disable DoubleClick in JTextField    coderanch.com

9. How to lock\disable JTextField?    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class DressingUpComponents { JTextField disabled, normal; JLabel label; public DressingUpComponents() { configureDisabledTextField(); normal = new JTextField("hello world"); configureLabel(); } private void configureDisabledTextField() { disabled = new JTextField("hello world"); disabled.setEnabled(false); Color bgColor = UIManager.getColor("TextField.background"); disabled.setBackground(bgColor); Color fgColor = UIManager.getColor("TextField.foreground"); disabled.setDisabledTextColor(fgColor); disabled.setBorder(BorderFactory.createEtchedBorder()); } private void configureLabel() { label = new JLabel("hello world"); label.setBorder(BorderFactory.createEtchedBorder()); label.setOpaque(true); // required ...





10. How to disable selection in a JTextField?    coderanch.com

Hi Micheal, thanks for your help. Well I guess I've made a mistake by adding "by mouse" in the previous post. Actually I wanna prevent any operation which can select part of or the whole text. By not adding a motion listener we prevent mouse to do it but still we can use shift and arrow key to select it. Is ...

12. grey out Jtextfield when disabled.    coderanch.com

Perhaps it's L&F-dependent, but when I run this class, the disabled jtextfield is grayed-out. import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public class GreyTextField { private static void createAndShowUI() { JTextField tField1 = new JTextField("foo", 10); JTextField tField2 = new JTextField("bar", 10); tField1.setEnabled(false); JPanel panel = new JPanel(); panel.add(tField1); panel.add(tField2); JFrame frame = new JFrame("GreyTextField"); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public ...

13. ? JTextField disabled bg color sometimes grey & sometimes white on Windows Lk/Feel !?!?    coderanch.com

Still would love some help but pretty sure I noticed some more interesting behaviour. If a value has not yet been set on the text field(by the user or typing or by me calling setText("hey") ), then I can call setEnabled(true/false) all day long and it will toggle the background color between grayish(disabled) and white(enabled). BUT as soon as a value ...