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 329 of 745
 
			
			158 Views
While creating vertical slider, we can set custom values as well. Let us take three integer variable and set the int values for min, max as well as the initial value of the slider −int val = 50; int min = 0; int max = 100;Set it to the slider while creating a new slider. Here, we have set the constant to be VERTICAL, since we are creating a vertical slider −JSlider slider = new JSlider(JSlider.VERTICAL, min, max, val);The following is an example to create a vertical slider with custom values −Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import ... Read More
 
			
			279 Views
While creating horizontal slider, we can set custom values as well. Let us take three integer variable and set the int values for min, max as well as the initial value of the slider −int val = 75; int min = 0; int max = 100;Set it to the slider while creating a new slider. Here, we have set the constant to be HORIZONTAL, since we are creating a horizontal slider −JSlider slider = new JSlider(JSlider.HORIZONTAL, min, max, val);The following is an example to create a horizontal slider with custom min, max and initial value −Examplepackage my; import java.awt.Color; import ... Read More
 
			
			276 Views
Use SpinnerNumberModel to create a spinner with value as numbers −SpinnerModel value = new SpinnerNumberModel(10, 0, 20, 1);Now set the values −JSpinner spinner = new JSpinner(value);The following is an example to create a JSpinner with values as numbers −Examplepackage my; import java.awt.Font; import javax.swing.*; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame("Spinner Demo"); SpinnerModel value = new SpinnerNumberModel(10, 0, 20, 1); JSpinner spinner = new JSpinner(value); spinner.setBounds(50, 80, 70, 100); frame.add(spinner); frame.setSize(550,300); frame.setLayout(null); frame.setVisible(true); } }This will produce the following output −
 
			
			134 Views
Let’s say we have set the following values for JProgressBar −int min = 0; int max = 1000; progressBar = new JProgressBar(min, max);Now, get the above values and display in the Console −int value = progressBar.getValue(); System.out.println("Value = "+value); System.out.println("Minimum = "+progressBar.getMinimum()); System.out.println("Maximum = "+progressBar.getMaximum());The following is an example to get the values of a progress bar component −Examplepackage my; import javax.swing.*; public class SwingDemo extends JFrame { JProgressBar progressBar; int i = 0; SwingDemo() { int min = 0; int max = 1000; progressBar = new JProgressBar(min, ... Read More
 
			
			96 Views
The getModel() method is used to set all the values at once for a JProgressBar −int newVal = 5; int newMin = 0; int newMax = 100; progressBar.getModel().setRangeProperties(newVal, 0, newMin, newMax, true);The following is an example to set all the values at once using the model in a progress bar −Examplepackage my; import javax.swing.*; public class SwingDemo extends JFrame { JProgressBar progressBar; int i = 0; SwingDemo() { int min = 0; int max = 1000; progressBar = new JProgressBar(min, max); int newVal = 5; ... Read More
 
			
			489 Views
Let’s say we have set the tooltips for all the components using the following method in Java, for example −setToolTipText("Enter Age");Here, we have already enabled tooltips for all the components using the setToolTipText(). But, after enabling all of them, we disabled the tooltips using the following −ToolTipManager.sharedInstance().setEnabled(false);The following is an example to disable Tooltip for a component with an already enabled tooltip −Examplepackage my; import java.awt.GraphicsEnvironment; import java.awt.GridLayout; import java.awt.Point; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.ToolTipManager; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame.setDefaultLookAndFeelDecorated(true); ... Read More
 
			
			2K+ Views
To select more than one row in a JTable, use the setRowSelectionInterval() method. Here, set the indexes as interval for one end as well as other end.For multiple rows in a range, set the range. Here, we are selecting rows from index 1 to index 2 i.e. two rows −table.setRowSelectionInterval(1, 2);The following is an example to select more than one row at a time in a JTable −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.ListSelectionModel; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String[] args) { JFrame ... Read More
 
			
			663 Views
To select the first column in a JTable, use the setColumnSelectionInterval() method. Here, set the indexes as interval for one end as well as other end.For the first column, set the range as 0 and 0 since we want to only select the first column with index 0 −table.setColumnSelectionInterval(0, 0);The following is an example to select the first column in a JTable −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.ListSelectionModel; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame(); ... Read More
 
			
			3K+ Views
To make a canvas with Java Swing, use the Graphics2D class −public void paint(Graphics g) { Graphics2D graphic2d = (Graphics2D) g; graphic2d.setColor(Color.BLUE); graphic2d.fillRect(100, 50, 60, 80); }Above, we have created a rectangle and also added color to it.The following is an example to make a canvas in Java −Examplepackage my; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo extends JPanel { @Override public void paint(Graphics g) { Graphics2D graphic2d = (Graphics2D) g; graphic2d.setColor(Color.BLUE); graphic2d.fillRect(100, 50, 60, 80); } public ... Read More
 
			
			1K+ Views
Let us first set rows and columns for 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" };Now, set the above in a table as rows and columns −JTable table = new JTable(rec, header);Add the table in the panel −JPanel panel = new JPanel(); panel.add(new JScrollPane(table));The following is an example to create a table in a panel −Examplepackage my; ... Read More