Found 111 Articles for AWT

How to implement a program to count the number in Java?

raja
Updated on 10-Feb-2020 06:17:01

1K+ Views

The program uses a JLabel to hold a count label, a JTextField component to hold the number count, JButton component to create add, remove and reset buttons. When we click the add button, the count in the JTextField will get incremented by '1' and by clicking the remove button the count will be decremented by '1'. If we click the Reset button, it will reset the count to '0'.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class CounterTest extends JFrame implements ActionListener {    private JLabel label;    private JTextField text;    private JButton addBtn, removeBtn, resetBtn;    private int count;    public CounterTest() {       setTitle("Counter Test");   ... Read More

How can we set a border to JCheckBox in Java?

Alshifa Hasnain
Updated on 05-May-2025 18:33:11

665 Views

In this article, we will learn to set a border for JCheckBox in Java. JCheckBox is a Swing component that is commonly used in user interface selection. Although it includes a default appearance, we can customize its look by setting borders in order to have a good visual effect. What is a JCheckBox? A JCheckBox is a component that extends JToggleButton, and an object of JCheckBox represents an option that can be checked or unchecked. Syntax The following is the syntax for JCheckBox initialization: JCheckBox Checkbox_name = new JCheckBox(); If there are two or more options, then any ... Read More

How can we implement cut, copy and paste functionality of JTextField in Java?

Alshifa Hasnain
Updated on 21-Apr-2025 19:27:48

2K+ Views

A JTextField is a child class of the JTextComponent class through which a single line of text can be edited. Cut, copy, and paste operations of the JTextField component can be implemented using the cut(), copy(), and paste() methods. These are built-in methods in the JTextField class. built-in methodsJTextField class The Cut Operation Cutting involves removing selected text from the JTextField and placing it on the clipboard. Method Declaration: public void cut() { textField.cut(); } The Copy Operation Copying places a copy of the selected text on the clipboard without removing it from the JTextField. Method ... Read More

What are the differences between a JTextField and a JFormattedTextField in Java?

Alshifa Hasnain
Updated on 23-Apr-2025 17:18:55

1K+ Views

In Java, a JTextField can be used for plain text, whereas a JFormattedTextField is a class that extends JTextField, and it can be used to set any format to the text that it contains, phone numbers, e-mails, dates, etc. JTextField A JTextField is one of the most important components that allows the user to type an input text value in a single-line format. A JTextField can also generate the MouseListener and KeyListener interfaces. Syntax The following is the syntax for a JTextField initialization: JTextField textField = new JTextField(20); // 20 columns wide A JTextField can generate an ActionListener interface ... Read More

How can we implement a JLabel text with different color and font in Java?

raja
Updated on 29-Apr-2025 19:13:17

3K+ Views

In this article, we will learn to implement a JLabel text with different colors and fonts in Java. JLabel is commonly used for simple text display, it can be enhanced to show text with multiple colors and fonts. JLabel A JLabel class can extend the JComponent class, and an object of JLabel provides text instructions or information on a GUI. A JLabel can display a single line of read-only text, an image, or both text and an image. A JLabel can explicitly generate a PropertyChangeListener interface. Different Approaches The following are the two different approaches to implementing a JLabel text ... Read More

How can we insert multiple tabs into a single JTabbedPane in Java?

Alshifa Hasnain
Updated on 12-May-2025 18:39:17

499 Views

In this article, we will learn to insert multiple tabs into a single JTabbedPane in Java. The Java Swing's JTabbedPane enables you to group content into several tabs in one container. JTabbedPane A JTabbedPane is a component can extends the JComponent class, and we can able to see only one tab at a time. Each tab is associated with a single component that can be displayed when the tab is selected. Syntax Object declaration and instantiation using the Java class JTabbedPane: JTabbedPane tabbedPane = new JTabbedPane(); A JTabbedPane can generate a ChangeListener interface when a tab is ... Read More

How can we draw a rounded rectangle using the Graphics object in Java?

Alshifa Hasnain
Updated on 29-Apr-2025 19:12:17

5K+ Views

In this article, we will learn to draw a rounded rectangle using the Graphics object in Java. Drawing shapes is a basic feature of Java 2D graphics programming. Though the Graphics class offers methods for drawing common rectangles, drawing rounded rectangles involves some special techniques. Graphics Class In Java, the drawing takes place via a Graphics object, which is an instance of the java.awt.Graphics class. Each Graphics object has its own coordinate system, and all the methods of Graphics, including those for drawing Strings, lines, rectangles, circles, polygons, etc. We can get access to the Graphics object through the paint(Graphics ... Read More

How can we implement an editable JLabel in Java?

Alshifa Hasnain
Updated on 12-May-2025 18:25:26

451 Views

In this article, we will learn to implement an editable JLabel in Java. An editable JLabel is a label component that can be converted to an editable text field when clicked. JLabel A JLabel class can extend the JComponent class, and an object of JLabel provides text instructions or information on a GUI. A JLabel can display a single line of read-only text, an image, or both text and image. Syntax The following is the syntax for JLabel initialization: JLabel label = new JLabel("Tutorials Point"); A JLabel can explicitly generate a PropertyChangeListener interface. Methods The important methods of a ... Read More

How can we implement editable JComboBox in Java?

raja
Updated on 10-Feb-2020 06:34:10

1K+ Views

JComboBoxA JComboBox can extend JComponent class and it is a combination of a text field and a drop-down list from which the user can choose a value.If the text field portion of the control is editable, the user can enter a value in the field or edit a value retrieved from the drop-down list.By default, the user not allowed to edit the data in the text field portion of the JComboBox. If we want to allow the user to edit the text field, call setEditable(true) method.A JComboBox can generate an ActionListener, ChangeListener or ItemListener when the user actions on a combo box.A ... Read More

How can we implement a scrollable JPanel in Java?

raja
Updated on 10-Feb-2020 06:35:13

4K+ Views

JPanelA JPanel is a subclass of JComponent (a subclass of a Container class). Therefore, JPanel is also a Container.A JPanel is an empty area that can be used either to layout other components including other panels.In a JPanel, we can add fields, labels, buttons, checkboxes,  and images also.The Layout Managers such as FlowLayout, GridLayout, BorderLayout and other layout managers helps us to control the sizes, positions, and alignment of the components using JPanel.The important methods of a JPanel class are getAccessibleContext(), getUI(), updateUI() and paramString().We can also implement a JPanel with vertical and horizontal scrolls by adding the panel object to JScrollPane.Exampleimport java.awt.*; ... Read More

Previous 1 ... 6 7 8 9 10 ... 12 Next
Advertisements