×
Home
Jobs
Tools
Coding Ground
Current Affairs
UPSC Notes
Online Tutors
Whiteboard
Net Meeting
Tutorix
Login
Packages
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
Library
Videos
Q/A
eBooks
Login
Library
Videos
eBooks
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
Krantik Chavan
has Published
345
Answers
What happens when JDialog is set with Modality type APPLICATION_MODAL
Java 8
Object Oriented Programming
Programming
Krantik Chavan
Published on 06-May-2019 12:08:55
The JDialog Modality type APPLICATION_MODAL blocks all top-level windows and it has restrictions. The following is an example to set JDialog with Modality type APPLICATION_MODAL:Exampleimport java.awt.Cursor; import java.awt.Dialog.ModalityType; import java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; public class SwingDemo { public static void main(String[] args) ...
Read More
How to pre-select JComboBox item by index in Java?
Java 8
Object Oriented Programming
Programming
Krantik Chavan
Published on 06-May-2019 12:03:08
The following is an example to pre-select JComboBox item by index in Java. Here, we have selected the 3rd item by default i.e. whenever the Swing program will run, the third item would be visible instead of the 1st.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; ...
Read More
How to display the items in a JComboBox in Java
Java 8
Object Oriented Programming
Programming
Krantik Chavan
Published on 06-May-2019 11:58:24
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) { JPanel panel = new JPanel(new BorderLayout()); ...
Read More
How to hide and display JCombobox with a JCheckBox in Java?
Java 8
Object Oriented Programming
Programming
Krantik Chavan
Published on 06-May-2019 11:50:07
To toggle visibility with JCheckBox, use isVisible() method:JCheckBox toggleVisibility = new JCheckBox("Hide/Show"); toggleVisibility.setSelected(comboBox.isVisible()); toggleVisibility.addItemListener(e -> { comboBox.setVisible(e.getStateChange() == ItemEvent.SELECTED); });The following is an example to hide and display JCombobox with a JCheckBox in Java:Exampleimport java.awt.BorderLayout; import java.awt.event.ItemEvent; import javax.swing.*; public class SwingDemo { JFrame frame; SwingDemo(){ ...
Read More
Java Program to disable the first item on a JComboBox
Java 8
Object Oriented Programming
Programming
Krantik Chavan
Published on 06-May-2019 11:45:30
To disable the first index, on the click of a button, let us implement for index > 0 i.e. item 2:System.out.println("Index 0 (First Item) is disabled... "); comboBox.addItemListener(e -> { if (comboBox.getSelectedIndex() > 0) { System.out.println("Index = " + comboBox.getSelectedIndex()); } });By implementing above, we ...
Read More
How to align JLabel text vertically top in Java?
Java 8
Object Oriented Programming
Programming
Krantik Chavan
Published on 06-May-2019 11:33:07
Use the setVerticalAlignment() method to align JLabel text vertically to the top:JLabel label = label.setVerticalAlignment(JLabel.TOP);The following is an example to align JLabel text vertically to the top: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[]) { JFrame frame ...
Read More
How to set Mnemonic key for selection of each JCheckBox in Java?
Java 8
Object Oriented Programming
Programming
Krantik Chavan
Published on 06-May-2019 11:27:35
Mnemonic key is set so that a user can use Keyboard keys to check a CheckBox. For example, a key can be set with ALT:checkBox1.setMnemonic(KeyEvent.VK_F); checkBox2.setMnemonic(KeyEvent.VK_T); checkBox3.setMnemonic(KeyEvent.VK_R); checkBox4.setMnemonic(KeyEvent.VK_C); checkBox5.setMnemonic(KeyEvent.VK_A);Above, we have set key ALT+F for checkbox 1, key ALT+T for checkBox2, etc.The following is an example. Here, we have set ...
Read More
Handle JCheckBox Events with an ItemListener in Java
Java 8
Object Oriented Programming
Programming
Krantik Chavan
Published on 06-May-2019 11:12:47
Here, we have used ItemListener to handle JCheckBox events i.e. whenever any of the CheckBox is selected.For example; When any of the sports like Football CheckBox is checked, event is fired and a message is visible in the botton.The following is an example to handle JCheckBox events with an ItemListener:Exampleimport ...
Read More
How to get or set the selection state of JCheckBox in Java
Java 8
Object Oriented Programming
Programming
Krantik Chavan
Published on 06-May-2019 11:07:31
The following is an example to get or set the selection state of JCheckBox:Exampleimport java.awt.FlowLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; public class SwingDemo extends JFrame { public SwingDemo() { setSize(500, 500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout(FlowLayout.CENTER)); JCheckBox checkBox = new ...
Read More
How to disable JCheckBox if not checked in Java
Java 8
Object Oriented Programming
Programming
Krantik Chavan
Published on 06-May-2019 11:03:21
The following is an example to disable JCheckBox if not checked in Java:Exampleimport java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JCheckBox; import javax.swing.JOptionPane; public class SwingDemo { public static void main(String[] args) { JCheckBox checkBox = new JCheckBox("Demo", true); checkBox.addActionListener(new ActionListener() { ...
Read More
1
2
3
4
5
6
7
...
35
Next
Advertisements
Print
Add Notes
Bookmark this page
Report Error
Suggestions
Save
Close
Dashboard
Logout