
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9150 Articles for Object Oriented Programming

403 Views
To set the titled justification of the titled border, use the setTitleJustification() method. The following is an example to set the title justification of the titled border −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); LineBorder linedBorder = new LineBorder(Color.YELLOW); TitledBorder titledBorder = BorderFactory.createTitledBorder(linedBorder, "Demo Title"); titledBorder.setTitleJustification(TitledBorder.LEFT); JLabel label = new JLabel(); ... Read More

307 Views
Here, we will see how to add a title to an existing Line border. Let’s say we have a label and the border is to be set −LineBorder linedBorder = new LineBorder(Color.blue); TitledBorder titledBorder = BorderFactory.createTitledBorder(linedBorder, "Demo Title"); JLabel label = new JLabel(); label.setBorder(titledBorder);The following is an example to add a title to an existing line border −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ... Read More

170 Views
Yes, we can create nested TitledBorder. Let us first create a component for which we will set the border −JLabel label = new JLabel();Now, we will create the 1st border −TitledBorder border = BorderFactory.createTitledBorder("Top Border"); border.setTitlePosition(TitledBorder.TOP);Following is how we will creater border 2. We have set the 1st border here −TitledBorder border2 = new TitledBorder(border, "Bottom CENTER Border", TitledBorder.CENTER, TitledBorder.BOTTOM);Now, set it for the label component −label.setBorder(border2);The following is an example to create nested TitledBorder in Java −package my; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.TitledBorder; public class SwingDemo { public static ... Read More

119 Views
Let’s say the following is our JTextArea −JTextArea textArea = new JTextArea("This is demo text.");Now, get the font using the Font class getFont() method as shown below −Font font = textArea.getFont(); System.out.println("Font = "+font);The following is an example to get JTextArea font information in Java −Examplepackage my; import java.awt.Font; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo { SwingDemo(){ JFrame frame = new JFrame(); JTextArea textArea = new JTextArea("This is demo text."); Font font = textArea.getFont(); System.out.println("Font = "+font); frame.add(textArea); frame.setSize(550, 300); ... Read More

365 Views
To get the tab size from a JTextArea, you can use the getTabSize() method −textArea.getTabSize();We will assign it to int variable and display the size in the Console −int size = textArea.getTabSize(); System.out.println("Tab Size = "+size);The following is an example to set the tab size of a JTextArea −Examplepackage my; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo { SwingDemo() { JFrame frame = new JFrame(); JTextArea textArea = new JTextArea("This is demo text."); int size = textArea.getTabSize(); System.out.println("Tab Size = "+size); frame.add(textArea); ... Read More

276 Views
To make JTable single selectable in Java, you need to set the selection mode to be SINGE_SELECTION. Let’s say the following is our table −String[][] rec = { { "001", "Shirts", "40" }, { "002", "Trousers", "250" }, { "003", "Jeans", "25" }, { "004", "Applicances", "90" }, { "005", "Mobile Phones", "200" }, { "006", "Hard Disk", "150" }, }; String[] header = { "ID", "Product", "Quantity" }; JTable table = new JTable(rec, header);Set the selection more to make it single selectable with setSelectionMode() method −table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);Let us see an example to set the ... Read More

257 Views
Let’s say, we have selected a range of rows using addRowSelectionInterval() as shown in the demo screenshot −Now, we will deselect the above shown selected rows using removeRowSelectionInterval(). The range is to be set here for interval i.e rows 3 to 6 (index 2 to 5) will get deselected −table.removeRowSelectionInterval(2, 5);The following is our example to deselect a range of rows −Examplepackage my; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo { public static void main(String[] argv) throws Exception { DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel); ... Read More

196 Views
In this article, we will learn how to deselect a range of columns in a JTable using Java. JTable is a part of the Swing framework in Java, which is used to display and edit tables. Sometimes, we may want to deselect a specific range of columns after selecting columns in a table. This can be done by using the removeColumnSelectionInterval() method. Problem Statement Given a JTable with columns selected, write a Java program to deselect a range of columns from the table. Input A JTable with columns selected.Output The specified range of columns will be deselected. Steps to ... Read More

273 Views
Use the createLoweredBevelBorder() method to create a border with a lowered beveled edge. We will set it on the label component −JLabel label; label = new JLabel("This has a border with a lowered bevel edge!"); label.setBorder(BorderFactory.createLoweredBevelBorder());The following is an example to create a border with a lowered beveled edge −Examplepackage my; import javax.swing.BorderFactory; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Demo"); JLabel label; label = new JLabel("This has a border with a lowered bevel edge!"); ... Read More

1K+ Views
To disable a MenuItem, use the setEnabled() method and set it to FALSE. Let’s say we have the following MenuBar −JMenuBar menuBar = new JMenuBar();Now, create a Menu −JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);We will now create two MenuItems inside the above Menu −JMenuItem menuItem1 = new JMenuItem("New", KeyEvent.VK_N); fileMenu.add(menuItem1); JMenuItem menuItem2 = new JMenuItem("Open File", KeyEvent.VK_O); fileMenu.add(menuItem2);Now, let us disable the 2nd MenuItem −menuItem2.setEnabled(false);The following is an example to disable a MenuItem in Java −Examplepackage my; import java.awt.Color; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.UIManager; public class SwingDemo { public static void ... Read More