Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
Why does switch only show default output in console and *not* in the actual application?

I'm making my first java desktop application (which explains the lack of knowledge), when I run the project, the default output comes in the console instead of the actual project, wheras when the field is filled in correctly, it shows the output on the application/project.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String name = textBoxName.getText();
    switch (textBoxName.getText()) {
        case "":
            System.out.println("Name field cannot be blank!");
            break;
        default:
            Message.setText(name);         
    }
}
    
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Using System.out.println("your message here"); you are writing in the console, which is usually used to debug things. If you want to show the message to the user in a GUI interface, there is an useful class in Swing. Instead of System.out.println(); try

JOptionPane.showMessageDialog(null, "Name field cannot be blank!");

which will create a dialog with your message inside it and a button to close it. You can also specify a title of the dialog and the type of dialog like this:

JOptionPane.showMessageDialog(null, "Name field cannot be blank!", "Title of the message", JOptionPane.PLAIN_MESSAGE);

where instead of JOptionPane.PLAIN_MESSAGE you can also put ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE or QUESTION_MESSAGE.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!