
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

1K+ Views
To retrieve the value of a cell, use the getValueAt() method. As parameters, set the row and column index value for which you want the cell value −int rIndex = 5; // row index int cIndex = 1; // column index Object ob = table.getValueAt(rIndex, cIndex);Display the cell value in the Console −System.out.println("Value = "+ob);The following is an example to retrieve the value from a cell −Examplepackage my; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo { public static void main(String[] argv) throws Exception { JFrame frame ... Read More

683 Views
To set the margins i.e. row and columns margins between cells of a table, use the setIntercellSpacing() method −Dimension dim = new Dimension(50, 2); table.setIntercellSpacing(new Dimension(dim));Above, we have used the Dimension class −The following is an example to set margins between cells of a JTable cell −Examplepackage my; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo { public static void main(String[] argv) throws Exception { JFrame frame = new JFrame("Demo"); JPanel panel = new JPanel(); String data[][] = { ... Read More

349 Views
To display both horizontal and vertical grid lines in a table, use the setShowGrid() method and set it to true − The setShowGrid() method is used in graphical user interfaces or data visualization tools to control the visibility of grid lines in a component, like a chart or a table. table.setShowGrid(true); JTable is a class in the Java Swing library, part of the JFC(Java Foundation Classes). It creates and manages tables in a GUI(graphical user interface) application. Syntax void setShowGrid(boolean showGrid) Parameter showGrid: A boolean that determines grid line visibility for both horizontal and vertical lines is true ... Read More

1K+ Views
To set the grid color of a table, use the setGridColor() method.table.setGridColor(Color.yellow);Above, we have used the Color class to set the color.The following is an example to set the grid color of a table −Examplepackage my; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "ODI Rankings", TitledBorder.CENTER, TitledBorder.TOP)); String[][] rec = { ... Read More

201 Views
At first, set the setShowGrid() to FALSE to disable all the grid lines. To display only horizontal grid lines in a table, set the method setShowHorizontalLines() to TRUE. Let us first create a table with rows and columns −String[][] rec = { { "1", "Steve", "AUS" }, { "2", "Virat", "IND" }, { "3", "Kane", "NZ" }, { "4", "David", "AUS" }, { "5", "Ben", "ENG" }, { "6", "Eion", "ENG" }, }; String[] header = { "Rank", "Player", "Country" }; JTable table = new JTable(rec, header);Now, display only horizontal grid lines −table.setShowGrid(false); table.setShowHorizontalLines(true);The following ... Read More

219 Views
At first, set the setShowGrid() to FALSE to disable all the grid lines. To display only vertical grid lines in a table, set the method setShowVerticalLines() to TRUE. Let us first create a table with rows and columns −String[][] rec = { { "1", "Steve", "AUS" }, { "2", "Virat", "IND" }, { "3", "Kane", "NZ" }, { "4", "David", "AUS" }, { "5", "Ben", "ENG" }, { "6", "Eion", "ENG" }, }; String[] header = { "Rank", "Player", "Country" }; JTable table = new JTable(rec, header);Now, display only vertical grid lines −table.setShowGrid(false); table.setShowVerticalLines(true);The ... Read More

294 Views
Let’s say the following is our table −String[][] rec = { { "1", "Steve", "AUS" }, { "2", "Virat", "IND" }, { "3", "Kane", "NZ" }, { "4", "David", "AUS" }, { "5", "Ben", "ENG" }, { "6", "Eion", "ENG" }, }; String[] header = { "Rank", "Player", "Country" }; JTable table = new JTable(rec, header);Prevent displaying grid lines −table.setShowGrid(false);The following is an example to prevent displaying grid lines −Examplepackage my; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String[] ... Read More

963 Views
To expand JTree row to display all the nodes and child nodes, use the expandRow() method in Java. At first, create a node −DefaultMutableTreeNode node = new DefaultMutableTreeNode("Project");Now, add nodes to the node created above −DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("App"); DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Website"); DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("WebApp"); node.add(node1); node.add(node2); node.add(node3);Now, create more nodes and set them as child nodes for the nodes we creted above −DefaultMutableTreeNode one = new DefaultMutableTreeNode("Learning website"); DefaultMutableTreeNode two = new DefaultMutableTreeNode("Business website"); DefaultMutableTreeNode three = new DefaultMutableTreeNode("News publishing website"); DefaultMutableTreeNode four = new DefaultMutableTreeNode("Android app"); DefaultMutableTreeNode five = new DefaultMutableTreeNode("iOS app"); DefaultMutableTreeNode ... Read More

675 Views
To create a Titleless and Borderless JFrame, use the setUndecorated() method and set it to TRUE −JFrame frame = new JFrame("Register!"); frame.setUndecorated(true);The following is an example to create a titleless and borderless JFrame −Examplepackage my; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Register!"); JLabel label1, label2, label3; frame.setLayout(new GridLayout(2, 2)); label1 = new JLabel("Id", SwingConstants.CENTER); label2 = new JLabel("Age", SwingConstants.CENTER); ... Read More

4K+ Views
Differences between Map and WeakMapThe functional mechanism of Map and WeakMap is same but they have little differences.1) A WeakMap accepts only objects as keys whereas a Map, in addition to objects, accepts primitive datatype such as strings, numbers etc.2) WeakMap objects doesn't avert garbage collection if there are no references to the object which is acting like a key. Therefore there is no method to retrieve keys in WeakMap, whereas in Map there are methods such as Map.prototype.keys() to get the keys.3) There is no size property exists in WeakMap.MapIt is used to associate a key to a value ... Read More