×
Home
Jobs
Tools
Coding Ground
Current Affairs
UPSC Notes
Online Tutors
Whiteboard
Tutorix
Login
Categories
Java
JSP
iOS
HTML
Android
Python
C Programming
C++ Programming
C#
PHP
CSS
Javascript
jQuery
SAP
SAP HANA
Data Structure
RDBMS
MySQL
Mathematics
8085 Microprocessor
Operating System
Digital Electronics
Analysis of Algorithms
Mobile Development
Front End
Web Development
Selenium
MongoDB
Computer Network
General Topics
Q/A
Library
eBooks
Courses
Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Nancy Den
has Published
363
Answers
How to display the first element in a JComboBox in Java
Java 8
Object Oriented Programming
Programming
Nancy Den
Published on 06-May-2019 08:23:56
To display the first element in a JComboBox, use the getSelectedIndex():comboBox.setSelectedIndex(0);The following is an example to display the first element in a JComboBox in Java:Exampleimport java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; public class SwingDemo { public static void main(String[] args) ...
Read More
How to set tooltip text for JCheckBox in Java?
Java 8
Object Oriented Programming
Programming
Nancy Den
Published on 06-May-2019 08:09:13
For JCheckBox, use the following to set tooltip text:checkBox1.setToolTipText("Sports Football"); checkBox2.setToolTipText("Sports Tennis");Tooltip text is visible whenever you will place cursor on that particular text.The following is an example. Here, we have set the tooltip text for both the sports:Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingDemo { private ...
Read More
How to change JLabel background and foreground color in Java?
Java 8
Object Oriented Programming
Programming
Nancy Den
Published on 06-May-2019 08:05:43
To change the JLabel foreground and background color, use the following methods:JLabel label; label.setForeground(new Color(120, 90, 40)); label.setBackground(new Color(100, 20, 70));The following is an example to change JLabel background and foreground color:Exampleimport java.awt.Color; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo { public static void main(String args[]) { ...
Read More
How to filter non-null value in Java?
Java 8
Object Oriented Programming
Programming
Nancy Den
Published on 02-May-2019 08:29:20
Let’s say the following is our List with string elements:List<String> leagues = Arrays.asList("BBL", "IPL", "MLB", "FPL", "NBA", "NFL");Now, create a stream and filter elements that end with a specific letter:Stream<String> stream = leagues.stream().filter(leagueName -> leagueName.endsWith("L"));Now, use Objects::nonnull for non-null values:List<String> list = stream.filter(Objects::nonNull).collect(Collectors.toList());The following is an example to filter non-null ...
Read More
How to filter empty string values from a Java List?
Java 8
Object Oriented Programming
Programming
Nancy Den
Published on 02-May-2019 08:27:19
Let’s say we have a String List with an empty value. Here, we have empty array elements before Football and after Squash:List<String> sports = Arrays.asList("", "Football", "Cricket", "Tennis", "Squash", "", "Fencing", "Rugby");Now filter the empty string values. At first, we have used Predicate to negate values:Stream<String> stream = sports.stream(); Predicate<String> ...
Read More
How to count element after filtering in Java?
Java 8
Object Oriented Programming
Programming
Nancy Den
Published on 02-May-2019 08:24:13
Let’s say the following is the String List:List<String> list = new ArrayList<>(); list.add("Tom"); list.add("John"); list.add("David"); list.add("Paul"); list.add("Gayle"); list.add("Narine"); list.add("Joseph");Now, let’s say you need to filter elements beginning with a specific letter. For that, use filter() and startsWith():long res = list .stream() .filter((s) -> s.startsWith("J")) .count();We have also ...
Read More
How to convert Stream to TreeSet in Java?
Java 8
Object Oriented Programming
Programming
Nancy Den
Published on 02-May-2019 08:22:01
Let us first create a Stream:Stream<String> stream = Stream.of("UK", "US", "India", "Australia", "Armenia", "Canada", "Poland");Now convert Stream to TreeSet:Set<String> set = stream.collect(Collectors.toCollection(TreeSet::new));The following is an example to convert String to TreeSet in Java:Exampleimport java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) ...
Read More
How to convert string Stream to join them in Java?
Java 8
Object Oriented Programming
Programming
Nancy Den
Published on 02-May-2019 08:19:37
Let us create string Stream:Stream<String> stream = Stream.of("Bing Bang Theory", "Vampire Diaries", "Game of Thrones", "Homecoming");Convert the above string stream and join them with Collectors:final String str = stream.collect(Collectors.joining(" "));The following is an example to convert string Stream to join them:Exampleimport java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public ...
Read More
Java Program to convert Stream to typed array
Java 8
Object Oriented Programming
Programming
Nancy Den
Published on 02-May-2019 08:17:40
Let us first create a Stream:Stream<String> stream = Stream.of("Bing Bang Theory", "Vampire Diaries", "Game of Thrones", "Homecoming");Now convert the above stream to typed array:final String[] strArr = stream.toArray(String[]::new);The following is an example to convert Stream to typed array in Java:Exampleimport java.util.Arrays; import java.util.stream.Stream; public class Demo { public static ...
Read More
How to right align the text in a ComboBox in Java
Java 8
Object Oriented Programming
Programming
Nancy Den
Published on 02-May-2019 08:14:52
To right align the text in a JComboBox, use the following:ComponentOrientation.RIGHT_TO_LEFTThe following is an example to right align the text in a ComboBox:Exampleimport java.awt.Component; import java.awt.ComponentOrientation; import javax.swing.DefaultListCellRenderer; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JList; public class SwingDemo extends JFrame { public SwingDemo() { JComboBox<String> combo = ...
Read More
1
2
3
4
5
6
7
...
37
Next
Advertisements
Print
Add Notes
Bookmark this page
Report Error
Suggestions
Save
Close
Dashboard
Logout