Found 9150 Articles for Object Oriented Programming

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

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

2K+ Views

JTable component in Swing provides an effective method for showing and editing tabular information. JTable automatically supports re-ordering columns through dragging of column headers by default. In this article, we will learn to prevent the re-ordering of columns of a JTable in Java. JTable A JTable is a subclass of the JComponent class, and it can be used to create a table with information displayed in multiple rows and columns. Syntax The following is the syntax for JTable initialization: JTable table = new JTable(data, columnNames); When a value is selected from a JTable, a TableModelEvent is generated, which is handled ... Read More

How can we implement a rounded JTextField in Java?

Alshifa Hasnain
Updated on 09-Jun-2025 14:20:34

3K+ Views

In this article, we will learn to implement a rounded JTextField in Java. The JtextField is rectangular in shape, and to create a custom JTextField with rounded corners, we will use the RoundRectangle2D class and with the help of fillRoundRect() and drawRoundRect() methods in Java Swing. What is a JTextField? A JTextField is a subclass of the JTextComponent class, and it is one of the most important components that allows the user to an input text value in a single-line format.  Below is the graphical representation of a JTextField:  A JTextField class will generate an ActionListener interface when we ... Read More

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

raja
Updated on 14-Apr-2025 19:20:26

4K+ Views

In this article, we will learn to sort a JTable on a particular column in Java. Data sorting in a JTable is something that most Java Swing applications require. If the users can sort table data by clicking on column headers, it improves the experience greatly. What is a JTable? 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. Syntax The following is the syntax: JTable table = new JTable(data, columnNames); A JTable can generate different ... Read More

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

Alshifa Hasnain
Updated on 09-Jun-2025 14:20:00

2K+ Views

In this article, we will learn to show/hide the echo character of a JPasswordField in Java. The password in this will be hidden with *. And we will be using the setEchoChar() method to toggle between hidden and visible text in a Swing based application. What is a JPasswordField? 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. What is the echo ... Read More

What is the use of exec() regex method in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

122 Views

exec()The exec() method is a regex method. It searches a string for a specified pattern and, unlike test() regex method, returns the found text as an object. If there are no matches it will give null as an output. Let's discuss it in detail.Example-1In the following example, a variable pattern "est" is checked through the exec() method. The exec() regex method, after scrutinizing the given pattern throughout the text, returned the pattern as an object.Live Demo var obj = /est/.exec("Tutorix is the best e-learning platform"); document.write( "The object is ... Read More

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

Alshifa Hasnain
Updated on 15-May-2025 11:25:12

3K+ Views

While using JTables in Java Swing, you may have cases where you would require displaying or hiding the column headers dynamically. In this article, we will learn how to show/hide the table header of a JTable in Java. JTable A JTable is a subclass of the JComponent class for displaying complex data structures. A JTable can follow the Model View Controller (MVC) design pattern to display the data in rows and columns. DefaultTableModel The DefaultTableModel class is a subclass of AbstractTableModel, and it can be used to add rows and columns to a JTable dynamically. The DefaultTableCellRenderer class can ... Read More

What is the use of test() method in JavaScript?

vineeth.mariserla
Updated on 01-Jul-2020 10:52:34

1K+ Views

The test() method is a regular expression method. It searches a string for a pattern, and returns true or false, depending on the result. If it encountered the given pattern it returns true, else returns false. It is case sensitive. Let's discuss it in detail.Example-1In the following example, a text named "Tutorix is the best e-learning platform" is given and a pattern "Tu" is checked whether it is present or not. Since the pattern is present the test() method returned true as output.Live Demo Tutorix is the best e-learning platform    var text = document.getElementById("text").innerHTML;    document.getElementById("test").innerHTML = /Tu/.test(text); ... Read More

How to display the different font items inside a JComboBox in Java?

Alshifa Hasnain
Updated on 18-Apr-2025 16:04:32

566 Views

In this article, we will learn to display the different font items inside a JComboBox in Java. The Swing framework provides a powerful JComboBox component that allows users to select an object from a drop-down list. What is a JComboBox? A JComboBox is a subclass of the JComponent class, and it is a combination of a text field and a drop-down list from which the user can choose a value. A JComboBox can generate an ActionListener, ChangeListener, and ItemListener interfaces when the user interacts with a combo box. Syntax The following is the syntax: JComboBox Box_Name = new JComboBox(array); Problem ... Read More

What is importance of startsWith() method in JavaScript?

vineeth.mariserla
Updated on 01-Jul-2020 10:54:31

140 Views

To know Whether a string starts with a particular character or a string indexOf() method is used. But in the advanced applications, this method is obsolete. So, ES6 has provided us with startsWith() method to perform those advanced tasks.In the following example, the IndexOf() method is used to find whether the string is started with a particular character or not.ExampleLive Demo    var text = 'Tutorialspoint'    document.write(text.indexOf('T') === 0); OutputtrueIn the following example, instead of indexOf() method,  startsWith() method is used to find whether the string is started with a particular string or not.ExampleLive Demo ... Read More

How to set a tooltip text for each item of a JList in Java?

Alshifa Hasnain
Updated on 07-May-2025 18:33:46

760 Views

In this article, we will learn to set a tooltip text for each item of a JList in Java. Tooltips give meaningful information as users hover over UI components. Swing's JList does not support tooltips on a per-item basis, so it will involve some customization. What is JList? A JList is a subclass of the JComponent class, and it can be used to display a list of objects that allows the user to select one or more items. A JList can generate a ListSelectionListener interface and needs to implement the abstract method valueChanged(). Syntax The following is the syntax for ... Read More

Advertisements