Found 112 Articles for AWT

What is the importance of a Cursor class in Java?

raja
Updated on 10-Feb-2020 09:03:57

2K+ Views

A Cursor is a subclass of Object class and it can be defined as point or indicator on the screen. A Cursor is used to select the input from the system that the user operates with the mouse. Different types of cursors available in the Cursor class are DEFAULT_CURSOR, CROSSHAIR_CURSOR, HAND_CURSOR, TEXT_CURSOR, WAIT_CURSOR and etc. The important methods of Cursor class are getDefaultCursor(), getName(), getPredefinedCursor(), getSystemCustomCursor() and getType().Exampleimport java.awt.*; import javax.swing.*; public class CursorTest extends JFrame {    public CursorTest() {       setTitle("Cursor Test");       Cursor cursor = new Cursor(Cursor.HAND_CURSOR); // HAND CURSOR       setCursor(cursor);       setSize(375, 250); ... Read More

How can we disable cut, copy and paste functionality of a JTextArea in Java?

raja
Updated on 10-Feb-2020 09:07:38

481 Views

A JTextArea is a subclass of the JTextComponent class and it is a multi-line text component to display the text or allow a user to enter the text. A JTextArea can generate a CaretListener interface when we are trying to implement the functionality of the JTextArea. By default, the JTextArea class can support cut, copy and paste functionality, we can also disable or turn off the functionality of cut, copy and paste by using the getInputMap().put() method of JTextArea class. We can use KeyStroke.getKeyStroke("control X") for cut, KeyStroke.getKeyStroke("control C") for copy and KeyStroke.getKeyStroke("control V") for paste.Example.import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JTextAreaCutCopyPasteDisableTest extends JFrame {    private JTextArea ... Read More

How can we implement a long text of the JOptionPane message dialog in Java?

raja
Updated on 10-Feb-2020 07:33:26

370 Views

A JOptionPane is a subclass of the JComponent class which includes static methods for creating and customizing modal dialog boxes. A JOptionPane class can be used instead of a JDialog class to minimize the complexity of the code. The JOptionPane displays the dialog boxes with one of the four standard icons (question, information, warning,  and error) or the custom icons specified by the user. By default, the JOptionPane message dialogs can support a single-line text, we can also implement a JOptionPane message dialog with a long text by customizing the JTextArea class.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class JOptionPaneScrollTextMessage extends JFrame {    private JButton btn; ... Read More

How can we detect the double click events of a JTable row in Java?

raja
Updated on 11-Feb-2020 12:07:15

3K+ Views

A JTable is a subclass of JComponent for displaying complex data structures. A JTable can follow the Model View Controller (MVC) design pattern for displaying the data in rows and columns. A JTable can generate TableModelListener, TableColumnModelListener, ListSelectionListener, CellEditorListener and RowSorterListener interfaces. We can detect the double click events of a JTable by using a MouseAdapter class or MouseListener interface. We can set the getClickCount() value to '2' of a MouseEvent class for detecting the double click events of a JTable.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public final class DoublClickJTableRowTest extends JFrame {    private JTable table;    private JScrollPane scrollPane;    public DoublClickJTableRowTest() {   ... Read More

How can we highlight the selected tab of a JTabbedPane in Java?

raja
Updated on 10-Feb-2020 07:37:35

430 Views

A JTabbedPane is a subclass of JComponent class and it can provide easy access to more than one panel. Each tab is associated with a single component that can be displayed when the tab is selected. A JTabbedPane can generate a ChangeListener interface when a tab is selected. We can highlight a selected tab with a particular color of a JTabbedPane by using the static method put() of the UIManager class.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class SelectedJTabbedPaneTest extends JFrame implements ActionListener {    private JTabbedPane tabbedPane;    int tab = 0;    public SelectedJTabbedPaneTest() {       setTitle("SelectedJTabbedPane Test");       setLayout(new BorderLayout()); ... Read More

How can we prevent the re-ordering columns of a JTable in Java?

raja
Updated on 10-Feb-2020 07:40:06

836 Views

A JTable is a subclass of JComponent class and it can be used to create a table with information displayed in multiple rows and columns. When a value is selected from a JTable, a TableModelEvent is generated, which is handled by implementing a TableModelListener interface. By default, we can do the re-ordering of columns in a JTable. We can not allow the user to reorder columns by using table.getTableHeader().setReorderingAllowed() method and set the value as false.Exampleimport java.awt.*; import javax.swing.*; public final class JTableColumnReorderingTest extends JFrame {    JTable table;    JScrollPane scrollPane;    public JTableColumnReorderingTest() {       setTitle("JTableColumnReordering Test");       String[] ... Read More

How can we implement a rounded JTextField in Java?

raja
Updated on 10-Feb-2020 07:56:50

2K+ Views

A JTextField is a subclass of JTextComponent class and it is one of the most important components that allow the user to an input text value in a single-line format. A JTextField class will generate an ActionListener interface when we trying to enter some input inside it. The important methods of a JTextField class are setText(), getText(), setEnabled() and etc. By default, a JTextfield has a rectangle shape, we can also implement a round-shaped JTextField by using the RoundRectangle2D class and need to override the paintComponent() method.Exampleimport java.awt.*; import javax.swing.*; import java.awt.geom.*; public class RoundedJTextFieldTest extends JFrame {    private JTextField tf;    public RoundedJTextFieldTest() {     ... Read More

How can we sort a JTable on a particular column in Java?

raja
Updated on 10-Feb-2020 07:58:40

3K+ Views

A JTable is a subclass of JComponent class for displaying complex data structures. A JTable component can follow the Model View Controller (MVC) design pattern for displaying the data in rows and columns. A JTable can generate TableModelListener, TableColumnModelListener, ListSelectionListener, CellEditorListener, RowSorterListener interfaces. We can sort a JTable in a particular column by using the method setAutoCreateRowSorter() and set to true of JTable class.Exampleimport java.awt.*; import javax.swing.*; public final class JTableSorterTest extends JFrame {    private JTable table;    private JScrollPane scrollPane;    public JTableSorterTest() {       setTitle("JTableHeaderHide Test");       String[] columnNames = {"Name", "Age", "City"};       ... Read More

How can we show/hide the echo character of a JPasswordField in Java?

raja
Updated on 10-Feb-2020 07:54:35

1K+ Views

A JPasswordField is a subclass of JTextField and each character entered in a JPasswordField can be replaced by an echo character. This allows confidential input for passwords. By default, the echo character is the asterisk(*). The important methods of JPasswordField are get password(),  getText(), getAccessibleContext() and etc. By default, JPasswordField can show the echo characters. We can hide the echo characters and show the original text to the use by click on JCheckBox.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public final class ShowJPasswordTest extends JPanel {    private JPasswordField pf1;    private JCheckBox jcb;    private JPanel panel;    public ShowJPasswordTest() {       pf1 = makePasswordField();     ... Read More

How can we show/hide the table header of a JTable in Java?

raja
Updated on 10-Feb-2020 07:44:45

2K+ Views

A JTable is a subclass of JComponent class for displaying complex data structures. A JTable can follow the Model View Controller (MVC) design pattern for displaying the data in rows and columns. The DefaultTableModel class is a subclass of AbstractTableModel and it can be used to add the rows and columns to a JTable dynamically. The DefaultTableCellRenderer class can extend JLabel class and it can be used to add images, colored text and etc. inside the JTable cell. We can hide the table header of a JTable by unchecking the JCheckBox and show the table header of a JTable by clicking the JCheckBox.Exampleimport java.awt.*; import javax.swing.*; import javax.swing.table.*; public final class JTableHeaderHideTest extends ... Read More

Previous 1 ... 3 4 5 6 7 ... 12 Next
Advertisements