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
 
Java Articles - Page 327 of 745
 
			
			333 Views
To set arrow buttons in a frame, let us first create a frame −JFrame frame = new JFrame();Now, set the layout for the frame wherein all the arrow buttons would be displayed −frame.setLayout(new GridLayout(0, 5));Set the arrow buttons for all the locations −frame.add(new BasicArrowButton(BasicArrowButton.EAST)); frame.add(new BasicArrowButton(BasicArrowButton.NORTH)); frame.add(new BasicArrowButton(BasicArrowButton.SOUTH)); frame.add(new BasicArrowButton(BasicArrowButton.WEST));The following is an example to set all the arrow buttons in a frame −Examplepackage my; import java.awt.GridLayout; import javax.swing.Box; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.plaf.basic.BasicArrowButton; public class SwingDemo { public static void main(String[] args) { JButton button1 = new JButton("One"); ... Read More
 
			
			23K+ Views
To add icon to a button, use the Icon class, which will allow you to add an image to the button.We are creating a button wherein we are adding an icon with Icon class −Icon icon = new ImageIcon("E:\editicon.PNG"); JButton button7 = new JButton(icon);Above, we have set icon for button 7.The following is an example to add icon to JButton−Examplepackage my; import javax.swing.Box; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo { public static void main(String[] args) { JButton button1 = new JButton("One"); JButton button2 = new JButton("Two"); ... Read More
 
			
			382 Views
To allow multiple selection of nodes not necessarily contiguous, set the selection mode for tree to be DISCONTIGUOUS_TREE_SELECTION −tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);The following is an example to allow multiple selection of nodes, which are not necessarily contigous −Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeSelectionModel; 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"); DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Electronics"); DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("Home Decor"); DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("Furniture"); node.add(node1); node.add(node2); node.add(node3); node.add(node4); DefaultMutableTreeNode one = new DefaultMutableTreeNode("Shirt"); DefaultMutableTreeNode two = new DefaultMutableTreeNode("Trousers"); DefaultMutableTreeNode three = new DefaultMutableTreeNode("Jeans"); DefaultMutableTreeNode four = new DefaultMutableTreeNode("Mobiles"); ... Read More
 
			
			692 Views
Let us first create a demo table −JTable table = new JTable(tableModel);Now, add a column to it −tableModel.addColumn("Languages");Add some rows to the table using insertRow() method −tableModel.insertRow(0, new Object[] { "CSS" }); tableModel.insertRow(0, new Object[] { "HTML5" }); tableModel.insertRow(0, new Object[] { "JavaScript" }); tableModel.insertRow(0, new Object[] { "jQuery" }); tableModel.insertRow(0, new Object[] { "AngularJS" });The following is an example to add a row to a table with DefaultTableModel −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(); ... Read More
 
			
			1K+ Views
To disable only the horizontal scrollbar in Java, use the JScrollPane.HORIZONTAL_SCROLLBAR_NEVER. Let’s say you created a Box with some button components. Now, create a JScrollPane −JScrollPane scrollPane = new JScrollPane();Set the Viewport view as Box −scrollPane.setViewportView(box);Now, disable the horizontal scrollbar −scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);The following is an example to disable only the horizontal scrollbar −Examplepackage my; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("Tutorials"); JButton ... Read More
 
			
			498 Views
Box is lightweight container that uses a BoxLayout object as its layout manager. To display components from left to right, use Box createHorizontalBox() method.Let us first create some button components −JButton button1 = new JButton("One"); JButton button2 = new JButton("Two"); JButton button3 = new JButton("Three"); JButton button4 = new JButton("Four"); JButton button5 = new JButton("Five"); JButton button6 = new JButton("Six");Now, crate a Box and align all the buttons from left to right −Box box = Box.createHorizontalBox(); box.add(button1); box.add(button2); box.add(button3); box.add(button4); box.add(button5); box.add(button6);The following is an example to create a Box to display components from left to right −Examplepackage my; import ... Read More
 
			
			231 Views
Use the getPreviousNode() method to get the previous node of this node in Java. Here, we are displaying the previous node of child node “eight” −System.out.println("Get Previous Node = "+eight.getPreviousNode());The following is an example to get the previous node from a JTree −Examplepackage 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 (Product2 - ... Read More
 
			
			278 Views
In this article, we will learn how to set the extent of a JSlider using Java Swing. The extent defines the size of the range that the slider's knob can move within, restricting its movement past a certain point. JSlider JSlider is a component in Java Swing that provides a visual way to select a value by sliding a knob within a specified range. The setExtent() method in JSlider sets the size of the range that the knob covers, which controls how far it can move. setExtent() method The setExtent() method in Java is used to: ... Read More
 
			
			826 Views
To disable auto resizing, you need to use the setAutoResizeMode() method. After that, set the table to AUTO_RESIZE_OFF.Let’s say the following is our table −String[][] rec = { { "1", "Virat", "840" }, { "2", "David", "835" }, { "3", "Shikhar", "656" }, { "4", "Steve", "530" }, { "5", "Kane", "515" }, { "6", "Eion", "509" }, { "7", "AB de Villiers", "498" }, { "8", "Quinton", "470" }, { "9", "Glenn", "410" }, { "10", "Tom", "360" }, { "11", "Johnny", "320" }, { "12", "Shreyas", ... Read More
 
			
			966 Views
To display horizontal grid lines in a table, use the setShowHorizontalLines() method and set it to TRUE. Let us first create a 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);Now, let us display vertical grid lines −table.setShowHorizontalLines(true);You can also give a color to these lines −table.setGridColor(Color.orange);The following is an example to display ... Read More