Java examples on Java Swing
- How do I change JFrame image icon?
- How do I add key listener event handler to JTextField?
- How do I handle mouse button click event?
- How do I use JFormattedTextField to format user input?
- How do I display an image in JButton?
- How do I add an action listener to JComboBox?
- How do I get or set the state of JCheckBox?
- How do I handle a window closing event?
- How do I format JTextField's text to uppercase?
- How do I handle JFrame window events?
- How do I add items and remove items from JComboBox?
- How do I format JLabel using HTML?
- How do I create undecorated frame?
- How do I create JComboBox?
- How do I right justified JTextField contents?
- How do I close a JFrame application?
- How do I create JLabel with an image icon?
- How do I handle mouse wheel event?
- How do I render boolean value as checkbox in JTable component?
- How do I make a centered JFrame?
- How do I programmatically select JTable's rows?
- How do I handle mouse event in swing?
- How do I get items of JComboBox?
- How do I use SwingWorker to perform background tasks?
- How do I set and get the selected item in JComboBox?
- How do I set the look and feel for swing application?
- How do I get the items of a JList components?
- How do I create a ButtonGroup for radio buttons?
- How do I get the system look and feel?
- How do I customize JButton icons?
- How do I change the cursor shape?
- How do I disable JFrame close button?
- How do I set a tool tip for swing component?
- How do I customize JCheckBox icons?
- How do I get the selected cells in JTable component?
- How do I change color of selected node in JTree?
- How do I place swing component using absolute coordinates?
- How do I create JTree with different icons for each node?
- How do I append text to JTextArea?
- How do I get the available swing look and feel?
- How do I arrange the swing component using GridLayout?
- How do I arrange the swing component using FlowLayout?
- How do I handle mouse motion event?
- How do I replace text in the JTextArea?
- How do I disable or enable JTable cell selection?
- How do I select all text in JTextArea?
- How do I create JCheckBox component?
- How do I create a JList component?
- How do I create JSpinner component with date value?
- How do I change JTabbedPane tab placement position?
- How do I add background image in JTextPane?
- How do I create Border for swing component?
- How do I insert a text in a specified position in JTextArea?
- How do I get the selected nodes of a JTree?
- How do I right-align numbers data in JTable component?
- How do I disable / enable application tool tips?
- How do I create a JSpinner component?
- How do I expand or collapse all JTree nodes?
- How do I create a message dialog box?
- How do I detect tab selection changes in JTabbedPane?
- How do I create an uneditable JTextArea?
- How do I create JSpinner component with hour value?
- How do I arrange the swing component using BoxLayout?
- How do I scroll or wrap JTabbedPane tab layout?
- How do I create a multi lines tool tips?
- How do I change JTree default icons?
- How do I add icon to JTabbedPane tabs?
- How do I listening for changes to the selected item in JComboBox?
- How do I add selection listener to JTree?
- How do I assign keyboard shortcut to JTabbedPane tabs?
- How do I disable or enable tabs in JTabbedPane?
- How do I create a JSlider with custom labels?
- How do I set Swing Timer initial delay?
- How do I create a simple JTabbedPane?
- How do I get the JFrame of a component?
- How do I create a scrollable JTable component?
- How do I create a compound border?
- How do I determine if the menu of JComboBox is displayed?
- How do I associate JLabel component with a JTextField?
- How do I set the tab size in JTextArea?
- How do I create a table model for JTable component?
- How do I disable keyboard events in JTextArea?
- How do I wrap the text lines in JTextArea?
- How do I remove tabs from JTabbedPane?
- How do I set the colors of JTabbedPane tabs?
- How do I use a JSlider component?
- How do I create JRadioButton and define some action?
- How do I read text file into JTextArea?
- How do I remove JTree default icons?
- How do I programmatically select JTable's columns?
- How do I set the font and color of JTextArea?
- How do I create a JRadioButton component?
- How do I set and get the contents of JTextArea?
- How do I use JColorChooser component?
- How do I set or change JTable column width?
- How do I use Swing Timer class?
- How do I use a JTree component?
- How do I move focus from JTextArea using TAB key?
- How do I create a JSpinner with a SpinnerListModel?
- How do I set the cell width and height of a JList component?
- How do I set the JTable's selection mode?
- How do I add a title to a border?
- How do I create a vertical JSlider?
- How do I remove a node from JTree?
- How do I create a JTextArea?
- How do I add disabled icon for JTabbedPane tabs?
- How do I create a JSlider that snap to the closest tick mark?
- How do I create JLabel component?
- How do I allow row or column selection in JTable?
- How do I create a simple JTable component?
- How do I change the number of visible items in JComboBox?
- How do I reverse JSlider's value-range?
- How do I assign tool tips for JTabbedPane tabs?
- How do I flash the window taskbar in Swing?
- How do I change JFrame state programmatically?
- How do I create a single line JTextArea?
- How do I get the selected color from JColorChooser?
- How do I set the initial color of a JColorChooser?
- How to define JRadioButton label position?
How do I create an uneditable JTextArea?
The following example shows you how to set the property of the JTextArea so that it cannot be edited or modified. To make the JTextArea not editable call the setEditable() method and pass a false value as the parameter.
package org.kodejava.example.swing;
import javax.swing.*;
import java.awt.*;
public class TextAreaNotEditable extends JPanel {
public TextAreaNotEditable() {
initializeUI();
}
private void initializeUI() {
this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(400, 200));
JTextArea textArea = new JTextArea(5, 40);
textArea.setText("The quick brown fox jumps over the lazy dog.");
//
// By default the JTextAread is editable, calling
// setEditable(false) produce uneditable JTextArea.
//
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
this.add(scrollPane, BorderLayout.CENTER);
}
public static void showFrame() {
JPanel panel = new TextAreaNotEditable();
panel.setOpaque(true);
JFrame frame = new JFrame("JTextArea Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TextAreaNotEditable.showFrame();
}
});
}
}