
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

152 Views
Use the setTabPlacement() method to set the tab location. To make it visible in the bottom, use the BOTTOM constant −JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);The following is an example to specify tab location to make it visible in the bottom −package my; import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Technologies"); JTabbedPane tabbedPane = new JTabbedPane(); JPanel panel1, panel2, panel3, panel4, panel5; panel1 = new JPanel(); panel2 = new JPanel(); ... Read More

1K+ Views
Let us first create a JTabbedPane −JTabbedPane tabbedPane = new JTabbedPane();Create some panels −JPanel panel1, panel2, panel3, panel4, panel5; panel1 = new JPanel(); panel2 = new JPanel(); panel3 = new JPanel(); panel4 = new JPanel(); panel5 = new JPanel();Now, add tabs using the addTab() method and set the panels as well in which the tabs would be visible −tabbedPane.addTab("PHP", panel1); tabbedPane.addTab("Blockchain ", panel2); tabbedPane.addTab("Matlab", panel3); tabbedPane.addTab("JSP ", panel4); tabbedPane.addTab("Servlet", panel5);The following is an example to add a tab in JTabbedPane −package my; import javax.swing.*; import java.awt.*; public class SwingDemo { public static void main(String args[]) { ... Read More

1K+ Views
For background and foreground color of the JTextPane, use the following −JTextPane textPane = new JTextPane(); textPane.setBackground(Color.blue); textPane.setBackground(Color.green);For font face, style and size, use the Font class and set the font −Font font = new Font("Serif", Font.ITALIC, 18); textPane.setFont(font);The following is an example to set font, style and color for text in JTextPane −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; public class SwingDemo { public static void main(String args[]) throws BadLocationException { JFrame frame = new JFrame("Demo"); ... Read More

248 Views
Use the getSiblingCount() method to get the number of siblings of a node in JTree. For example, let’s say we have a node, which isn’t a root node. For that, we will find the sibling count −node1.getSiblingCount()The following is an example to get the number of siblings of a node −package my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Demo"); DefaultMutableTreeNode node = new DefaultMutableTreeNode("Project"); DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("QA"); DefaultMutableTreeNode node2 ... Read More

323 Views
To get the number of levels above a node, use the getLevel() method. Following is an example for the root node “node” −node.getLevel()Note − The value 0 is returned if the node is a root node since there are zero levels above the root node.For other nodes, get the number of levels above a node as shown below with node3 −node3.getLevel()The following is an example to get the number of levels above a node in a JTree −package my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class SwingDemo { public static void main(String[] args) throws Exception { ... Read More

321 Views
To align two components in the same line, you need to set the contrainsts of the GridBagConstraints properly. Let’s say we have two components in panel1. Set the contraints using Insets as well −panel1.add(checkBox1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); panel1.add(checkBox2, new GridBagConstraints(1, 0, 1, 1, 2.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));The following is an example to set two components in the same line −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo { ... Read More

215 Views
At first, create a JDesktopPane −JDesktopPane desktopPane = new JDesktopPane();Now, create an Internal Frame −JInternalFrame intFrame = new JInternalFrame("Our Frame", true, true, true, true); intFrame.setBounds(50, 90, 200, 250);Set Pallette layer for JDesktopPane and add the Internal Frame to JDesktopPane −intFrame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE); desktopPane.add(intFrame, JDesktopPane.PALETTE_LAYER);The following is an example to set palette layer for JDesktopPane −package my; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; public class SwingDemo { public static void main(final String[] args) { JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JDesktopPane desktopPane = new JDesktopPane(); ... Read More

438 Views
At first, set an Internal Frame in the JDesktopPane −JDesktopPane desktopPane = new JDesktopPane(); JInternalFrame intFrame = new JInternalFrame("Our Frame", true, true, true, true); desktopPane.add(intFrame);Now, set the bounds of the Internal Frame −intFrame.setBounds(50, 90, 200, 250);Create two components −JLabel label = new JLabel(intFrame.getTitle(), JLabel.CENTER); JButton button = new JButton("Demo Button");Add the two components to the Internal Frame −intFrame.add(label, BorderLayout.CENTER); intFrame.add(button, BorderLayout.WEST);The following is an example to display multiple components in an internal frame −package my; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; public class SwingDemo { public static void main(final String[] args) { ... Read More

660 Views
To position components at the top fo the grid cell, set the GridBagConstraints. Let’s say we have a panel and within that two CheckBox components −JPanel panel1 = new JPanel(new GridBagLayout()); JCheckBox checkBox1 = new JCheckBox("Undergraduate"); JCheckBox checkBox2 = new JCheckBox("Graduate");Position the components now −panel1.add(checkBox1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.NORTH, new Insets(0, 0, 0, 0), 0, 0)); panel1.add(checkBox2, new GridBagConstraints(1, 0, 1, 1, 2.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NORTH, new Insets(0, 0, 0, 0), 0, 0));The following is an example to position component at the top of the grid cell with GridBagLayout −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; ... Read More

676 Views
At first, create a JDesktoPane −JDesktopPane desktopPane = new JDesktopPane();Now, create an Internal frame and add it to the JDesktopPane −JInternalFrame intFrame = new JInternalFrame("Our Frame", true, true, true, true); desktopPane.add(intFrame); The following is an example to add Internal Frame to a JDesktopPane − package my; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; public class SwingDemo { public static void main(final String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JDesktopPane desktopPane = new JDesktopPane(); JInternalFrame intFrame = new JInternalFrame("Our Frame", true, ... Read More