Handling empty input in swing text box

0 votes
I am taking input from user and I want to display a popup if the input is empty. How to do this in Java Swing?
Aug 27, 2019 in Java by Ritu
1,380 views

1 answer to this question.

0 votes
login_but.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e){

//System.out.print(F_user.getText());

String username = F_user.getText();

String password = F_pass.getText();

//System.out.print(password);

if(username.equals(""))

{

            JOptionPane.showMessageDialog(null,"Please enter username");

}

}

}

);
answered Aug 27, 2019 by Nila

Related Questions In Java

0 votes
1 answer

Swing Java create Text Box

In the frame, you can use the ...READ MORE

answered Aug 27, 2019 in Java by Kyle
1,258 views
0 votes
3 answers

How to read a Text File in Java?

You can use readAllLines and the join method to ...READ MORE

answered Jul 28, 2018 in Java by samarth295
• 2,220 points
2,455 views
0 votes
2 answers

How to read a text file in Java?

You can use Scanner class to read ...READ MORE

answered Aug 9, 2018 in Java by Parth
• 4,640 points
1,101 views
0 votes
1 answer

How to read text files from the Classpath in Java?

InputStream in = this.getClass().getClassLoader().getResourceAsStream("TextFile.txt"); InputStream in = this.getClass().getResourceAsStream("/TextFile.txt"); package ...READ MORE

answered May 8, 2018 in Java by Akrati
• 3,190 points
2,802 views
0 votes
1 answer

revalidate() vs repaint() in Java Swing

You need to call repaint() and revalidate() both in order ...READ MORE

answered Sep 20, 2018 in Java by code.reaper12
• 3,500 points
11,045 views
0 votes
1 answer

Fetching screen resolution using Java

You can fetch the screen resolution using the Toolkit.getScreenSize() method ...READ MORE

answered Sep 20, 2018 in Java by anto.trigg4
• 3,440 points
4,776 views
0 votes
1 answer

How to change selection listener in JComboBox?

It should respond to ActionListeners, like this: combo.addActionListener (new ...READ MORE

answered Nov 15, 2018 in Java by Frankie
• 9,830 points
1,142 views
0 votes
1 answer

Describe Heavy Weight Components Mean In Java Programming?

Heavy weight components like Abstract Window Toolkit ...READ MORE

answered Nov 28, 2018 in Java by Frankie
• 9,830 points
1,876 views
0 votes
1 answer

How to get text from text box in Swing?

You can add a Button listener here. ...READ MORE

answered Aug 27, 2019 in Java by Jishan
1,302 views
0 votes
1 answer

How to create text labels in Swing, Java?

In the frame, you can use the ...READ MORE

answered Aug 27, 2019 in Java by Jimmy
1,079 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP