- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write lambda expression code for SwingUtilities.invokeLater in Java?
An event handling code that runs on a special thread called event dispatch thread(EDT). Most of the code that invokes swing methods also runs on this EDT thread. It is necessary because most of swing object methods do not thread-safe. SwingUtilities is a utility class and has one important static method, invokeLater(). This method can be used to perform a task asynchronously in the AWT event dispatcher thread.
Syntax
public static void invokeLater(Runnable doRun)
Example
import javax.swing.*; public class InvokeLAterLambdaTest { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { // lambda expression code JFrame frame = new JFrame(); frame.setTitle("InvokeLater Lambda Test"); frame.getContentPane().add(new JLabel("Welcome to Tutorials Point", SwingConstants.CENTER)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(375, 250); frame.setLocationRelativeTo(null); frame.setVisible(true); }); // end of lambda } }
Output
- Related Articles
- How to write a conditional expression in lambda expression in Java?
- How to write the comparator as a lambda expression in Java?
- How can we write a multiline lambda expression in Java?
- How can we write Callable as a lambda expression in Java?
- How to use BooleanSupplier in lambda expression in Java?
- How to use IntSupplier in lambda expression in Java?
- How to implement IntBinaryOperator using lambda expression in Java?
- How to implement ToIntBiFunction using lambda expression in Java?
- How to implement ToDoubleBiFunction using lambda expression in Java?
- How to implement ToLongFunction using lambda expression in Java?
- How to implement ToLongBiFunction using lambda expression in Java?
- How to implement DoubleToIntFunction using lambda expression in Java?
- How to implement DoubleToLongFunction using lambda expression in Java?
- How to implement PropertyChangeListener using lambda expression in Java?
- How to implement IntFunction with lambda expression in Java?

Advertisements