- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 4338 Articles for Java 8
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
36 Views
We can set or disallow selection of cell in the table using setCellSelectionEnabled(). The following is an example. −If you want to allow selection of cell, then set the method to TRUE −table.setCellSelectionEnabled(true);If you want to disallow selection of cell, then set the method to FALSE −table.setCellSelectionEnabled(false);Here we have disallowed selection of a cell −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); tableModel.addColumn("Language/ Technology"); ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
245 Views
Let’s say we want the first child node of a node, then use the getFirstChild() method −node2.getFirstChild()Display the node’s first child on Console −System.out.println("The first child of node 2 = "+node2.getFirstChild());The following is an example to get this node’s first child 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 { JFrame frame = new JFrame("Demo"); DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products"); DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Clothing (Product1 - P66778)"); DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Accessories ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
1K+ Views
To create a date spinner, use the SpinnerDateModel class. Within that set the date format −Date today = new Date(); JSpinner spinner2 = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH)); JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner2, "dd/MM/yy"); spinner2.setEditor(editor);Above, we have set the Date format to be −dd/MM/yyThe following is an example to create a date spinner in Java −Examplepackage my; import java.awt.GridBagLayout; import java.util.Calendar; import java.util.Date; import javax.swing.*; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame("Spinner Demo"); JPanel panel = new JPanel(); JLabel label = new JLabel("Exam No."); JLabel label2 = new JLabel(" Appeared On"); panel.setLayout(new GridBagLayout()); int min = 0; int max = 10; int step = 1; ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
626 Views
To check if two nodes are equal, use the equals() method. Here, we are checking that node1 and node2 are equal or not.node1.equals(node2)The following is an example to check if two nodes are equal 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 { JFrame frame = new JFrame("Demo"); DefaultMutableTreeNode node = new DefaultMutableTreeNode("Website"); DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Videos"); DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Tutorials"); DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("QA"); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
261 Views
To set TabLayout Policy to JTabbedPane in Java when all the tabs does not fit in a single run, use the method setTabLayoutPolicy() −JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);Above we have set the constant to be SCROLL_TAB_LAYOUT, which is a tab layout policy for providing a subset of available tabs when all the tabs will not fit within a single run.The following is an example −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("Devices"); JTabbedPane tabbedPane = new JTabbedPane(); ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
612 Views
To change the background and foreground colors of tab, use the following methods −JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setBackground(Color.blue); tabbedPane.setForeground(Color.white);Above, we have used the Color class to set the colors for the background and foregroud colors −The following is an example to change the background and foreground colors of tab −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("Devices"); JTabbedPane tabbedPane = new JTabbedPane(); JPanel panel1, panel2, panel3, panel4, panel5; panel1 = new ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
110 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
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
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
957 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
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
139 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