
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
Krantik Chavan has Published 278 Articles

Krantik Chavan
924 Views
At first, let us create and array of strings:String[] strArr = { "ABCD", "AB", "ABCDEFG", "ABC", "A", "ABCDE", "ABCDEF", "ABCDEFGHIJ" };Now, for shortest to longest pattern, for example A, AB, ABC, ABCD, etc.; get the length of both the string arrays and work them like this:Arrays.sort(strArr, (str1, str2) -> str1.length() ... Read More

Krantik Chavan
2K+ Views
Here, we are sorting string array alphabetically by the initial character i.e. ‘J’ for ‘John’ will come after ‘Chris’ since the first character of ‘Chris’ is ‘C’.Let us first create a String array:String[] strArr = { "PQRS", "AB", "RSTUVW", "RST", "U", "UVWXY", "OUJBG" };Now, sort the string array based on ... Read More

Krantik Chavan
1K+ Views
To change display mode with Java Swings, use the setDisplayMode() method. Here, we have set the Display mode as:new DisplayMode(800, 600, 32, 60));Now, when you will run the program, the frame would be visible in a different resolution than the actual set resolution of your system.The following is an example ... Read More

Krantik Chavan
258 Views
To create Arrow Button at position north, use BasicArrowButton:BasicArrowButton arrow = new BasicArrowButton(BasicArrowButton.NORTH);Above, we have set the arrow to NORTH. Now add it to Panel:panel.add(arrow, BorderLayout.NORTH);The following is an example to create Arrow Button positioning North:Exampleimport java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.plaf.basic.BasicArrowButton; public class SwingDemo extends JPanel { ... Read More

Krantik Chavan
540 Views
To get the font metrics, use the FontMetrics class:Graphics2D graphics = (Graphics2D) gp.create(); String str = getWidth() + "(Width) x (Height)" + getHeight(); FontMetrics m = graphics.getFontMetrics();Now to display it:int xValue = (getWidth() - m.stringWidth(str)) / 2; int yValue = ((getHeight() - m.getHeight()) / 2) + m.getAscent(); graphics.drawString(str, xValue, yValue);The ... Read More

Krantik Chavan
709 Views
At first set the label on which you want the custom cursor to be visible on hover:JLabel label = new JLabel("Demo text! Hand cursor is visible on hover...");Now, set cursor to be visible as Hand Cursor instead of the default Cursor:label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));The following is an example to make a custom cursor ... Read More

Krantik Chavan
6K+ Views
To set fullscreen mode for your Java Swing application, use the setFullScreenWindow() method:GraphicsDevice device = graphics.getDefaultScreenDevice(); JFrame frame = new JFrame("Fullscreen"); device.setFullScreenWindow(frame);The following is an example to set fullscreen mode for Java Swing Application:Exampleimport java.awt.Color; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class SwingDemo { ... Read More

Krantik Chavan
260 Views
To set Titled Border to Panel, let us first create a Panel for our Java Swing Application:JPanel panel = new Jpanel(new BorderLayout());Now, set the titled border:panel.setBorder(new TitledBorder("Displaying Titled Border"));The following is an example to add Titled Border to Panel in Swing:Exampleimport java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.border.TitledBorder; ... Read More

Krantik Chavan
6K+ Views
Let us first create a Frame:JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setUndecorated(true);Now, create rounded borders:double x = 50; double y = 50; frame.setShape(new RoundRectangle2D.Double(x, y, 100, 100, 50, 50));The following is an example to create rounded borders in Swing:Exampleimport java.awt.geom.RoundRectangle2D; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo extends JPanel ... Read More

Krantik Chavan
285 Views
Let us first create a List:List emp = Arrays.asList( new Employee("John", "Marketing", 5), new Employee("David", "Operations", 10));We have class Employee with name, department and rank of employees.Now, create summary for the rank like count, average, sum, etc:IntSummaryStatistics summary = emp .stream() .collect(Collectors.summarizingInt(p -> p.rank));The following is an example to ... Read More