Why does this code gives me the error “imageicon cannot be converted to int”?












0














I have a problem with adding a picture to my messagescreen. The code works if I don't use textfields in my box, but it also worked with the textfields and without the picture... I really don't get why I'm getting this error:




incompatible types: ImageIcon cannot be converted to int




This is my code:



import javax.swing.JOptionPane; 
import javax.swing.JTextField;
import javax.swing.ImageIcon;

public class Input{

public static String geefInputNamen(){
JTextField veld1 = new JTextField();
JTextField veld2 = new JTextField();

Object velden = {
"Speler 1:", veld1,
"Speler 2:", veld2
};

ImageIcon icon = new ImageIcon("nbalivemobile.png");

JOptionPane.showConfirmDialog(null, velden, "Spelers vergelijken",
JOptionPane.OK_CANCEL_OPTION, icon);


String namen = new String[2];

namen[0] = veld1.getText();
namen[1] = veld2.getText();

return namen;
}
}


I'm new here, so I hope this is posted right. :)










share|improve this question




















  • 2




    Which line produces this error?
    – Mureinik
    Nov 20 at 21:31










  • line 18 produces the error.
    – Pieter De Smet
    Nov 20 at 21:44










  • I have no clue which one is that...
    – Antoniossss
    Nov 20 at 21:47










  • starting with joptionpane, but the question is already answered below
    – Pieter De Smet
    Nov 20 at 21:50










  • @PieterDeSmet, but the question is already answered below - then don't forget to "accept" the answer by clicking on the checkmark so people know the problem has been solved.
    – camickr
    Nov 21 at 0:33
















0














I have a problem with adding a picture to my messagescreen. The code works if I don't use textfields in my box, but it also worked with the textfields and without the picture... I really don't get why I'm getting this error:




incompatible types: ImageIcon cannot be converted to int




This is my code:



import javax.swing.JOptionPane; 
import javax.swing.JTextField;
import javax.swing.ImageIcon;

public class Input{

public static String geefInputNamen(){
JTextField veld1 = new JTextField();
JTextField veld2 = new JTextField();

Object velden = {
"Speler 1:", veld1,
"Speler 2:", veld2
};

ImageIcon icon = new ImageIcon("nbalivemobile.png");

JOptionPane.showConfirmDialog(null, velden, "Spelers vergelijken",
JOptionPane.OK_CANCEL_OPTION, icon);


String namen = new String[2];

namen[0] = veld1.getText();
namen[1] = veld2.getText();

return namen;
}
}


I'm new here, so I hope this is posted right. :)










share|improve this question




















  • 2




    Which line produces this error?
    – Mureinik
    Nov 20 at 21:31










  • line 18 produces the error.
    – Pieter De Smet
    Nov 20 at 21:44










  • I have no clue which one is that...
    – Antoniossss
    Nov 20 at 21:47










  • starting with joptionpane, but the question is already answered below
    – Pieter De Smet
    Nov 20 at 21:50










  • @PieterDeSmet, but the question is already answered below - then don't forget to "accept" the answer by clicking on the checkmark so people know the problem has been solved.
    – camickr
    Nov 21 at 0:33














0












0








0







I have a problem with adding a picture to my messagescreen. The code works if I don't use textfields in my box, but it also worked with the textfields and without the picture... I really don't get why I'm getting this error:




incompatible types: ImageIcon cannot be converted to int




This is my code:



import javax.swing.JOptionPane; 
import javax.swing.JTextField;
import javax.swing.ImageIcon;

public class Input{

public static String geefInputNamen(){
JTextField veld1 = new JTextField();
JTextField veld2 = new JTextField();

Object velden = {
"Speler 1:", veld1,
"Speler 2:", veld2
};

ImageIcon icon = new ImageIcon("nbalivemobile.png");

JOptionPane.showConfirmDialog(null, velden, "Spelers vergelijken",
JOptionPane.OK_CANCEL_OPTION, icon);


String namen = new String[2];

namen[0] = veld1.getText();
namen[1] = veld2.getText();

return namen;
}
}


I'm new here, so I hope this is posted right. :)










share|improve this question















I have a problem with adding a picture to my messagescreen. The code works if I don't use textfields in my box, but it also worked with the textfields and without the picture... I really don't get why I'm getting this error:




incompatible types: ImageIcon cannot be converted to int




This is my code:



import javax.swing.JOptionPane; 
import javax.swing.JTextField;
import javax.swing.ImageIcon;

public class Input{

public static String geefInputNamen(){
JTextField veld1 = new JTextField();
JTextField veld2 = new JTextField();

Object velden = {
"Speler 1:", veld1,
"Speler 2:", veld2
};

ImageIcon icon = new ImageIcon("nbalivemobile.png");

JOptionPane.showConfirmDialog(null, velden, "Spelers vergelijken",
JOptionPane.OK_CANCEL_OPTION, icon);


String namen = new String[2];

namen[0] = veld1.getText();
namen[1] = veld2.getText();

return namen;
}
}


I'm new here, so I hope this is posted right. :)







java swing compiler-errors imageicon






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 23:24









Andrew Thompson

153k27163338




153k27163338










asked Nov 20 at 21:29









Pieter De Smet

72




72








  • 2




    Which line produces this error?
    – Mureinik
    Nov 20 at 21:31










  • line 18 produces the error.
    – Pieter De Smet
    Nov 20 at 21:44










  • I have no clue which one is that...
    – Antoniossss
    Nov 20 at 21:47










  • starting with joptionpane, but the question is already answered below
    – Pieter De Smet
    Nov 20 at 21:50










  • @PieterDeSmet, but the question is already answered below - then don't forget to "accept" the answer by clicking on the checkmark so people know the problem has been solved.
    – camickr
    Nov 21 at 0:33














  • 2




    Which line produces this error?
    – Mureinik
    Nov 20 at 21:31










  • line 18 produces the error.
    – Pieter De Smet
    Nov 20 at 21:44










  • I have no clue which one is that...
    – Antoniossss
    Nov 20 at 21:47










  • starting with joptionpane, but the question is already answered below
    – Pieter De Smet
    Nov 20 at 21:50










  • @PieterDeSmet, but the question is already answered below - then don't forget to "accept" the answer by clicking on the checkmark so people know the problem has been solved.
    – camickr
    Nov 21 at 0:33








2




2




Which line produces this error?
– Mureinik
Nov 20 at 21:31




Which line produces this error?
– Mureinik
Nov 20 at 21:31












line 18 produces the error.
– Pieter De Smet
Nov 20 at 21:44




line 18 produces the error.
– Pieter De Smet
Nov 20 at 21:44












I have no clue which one is that...
– Antoniossss
Nov 20 at 21:47




I have no clue which one is that...
– Antoniossss
Nov 20 at 21:47












starting with joptionpane, but the question is already answered below
– Pieter De Smet
Nov 20 at 21:50




starting with joptionpane, but the question is already answered below
– Pieter De Smet
Nov 20 at 21:50












@PieterDeSmet, but the question is already answered below - then don't forget to "accept" the answer by clicking on the checkmark so people know the problem has been solved.
– camickr
Nov 21 at 0:33




@PieterDeSmet, but the question is already answered below - then don't forget to "accept" the answer by clicking on the checkmark so people know the problem has been solved.
– camickr
Nov 21 at 0:33












2 Answers
2






active

oldest

votes


















2














You are missing a parameter in your call to JOptionPane.showConfirmDialog, messageType which is an int and goes between optionType and icon. See the doc for JOptionPane.showConfirmDialog






share|improve this answer





























    2














    If you want to pass an Icon to showConfirmDialog, you need to use the 6 argument overload:



    JOptionPane.showConfirmDialog(
    null,
    velden,
    "Spelers vergelijken",
    JOptionPane.OK_CANCEL_OPTION,
    JOptionPane.PLAIN_MESSAGE, // Add this argument
    icon);


    I've used PLAIN_MESSAGE in this example, but you can use any one of ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE as specified in the API documentation.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401839%2fwhy-does-this-code-gives-me-the-error-imageicon-cannot-be-converted-to-int%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      You are missing a parameter in your call to JOptionPane.showConfirmDialog, messageType which is an int and goes between optionType and icon. See the doc for JOptionPane.showConfirmDialog






      share|improve this answer


























        2














        You are missing a parameter in your call to JOptionPane.showConfirmDialog, messageType which is an int and goes between optionType and icon. See the doc for JOptionPane.showConfirmDialog






        share|improve this answer
























          2












          2








          2






          You are missing a parameter in your call to JOptionPane.showConfirmDialog, messageType which is an int and goes between optionType and icon. See the doc for JOptionPane.showConfirmDialog






          share|improve this answer












          You are missing a parameter in your call to JOptionPane.showConfirmDialog, messageType which is an int and goes between optionType and icon. See the doc for JOptionPane.showConfirmDialog







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 21:37









          Joakim Danielson

          6,6053623




          6,6053623

























              2














              If you want to pass an Icon to showConfirmDialog, you need to use the 6 argument overload:



              JOptionPane.showConfirmDialog(
              null,
              velden,
              "Spelers vergelijken",
              JOptionPane.OK_CANCEL_OPTION,
              JOptionPane.PLAIN_MESSAGE, // Add this argument
              icon);


              I've used PLAIN_MESSAGE in this example, but you can use any one of ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE as specified in the API documentation.






              share|improve this answer


























                2














                If you want to pass an Icon to showConfirmDialog, you need to use the 6 argument overload:



                JOptionPane.showConfirmDialog(
                null,
                velden,
                "Spelers vergelijken",
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE, // Add this argument
                icon);


                I've used PLAIN_MESSAGE in this example, but you can use any one of ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE as specified in the API documentation.






                share|improve this answer
























                  2












                  2








                  2






                  If you want to pass an Icon to showConfirmDialog, you need to use the 6 argument overload:



                  JOptionPane.showConfirmDialog(
                  null,
                  velden,
                  "Spelers vergelijken",
                  JOptionPane.OK_CANCEL_OPTION,
                  JOptionPane.PLAIN_MESSAGE, // Add this argument
                  icon);


                  I've used PLAIN_MESSAGE in this example, but you can use any one of ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE as specified in the API documentation.






                  share|improve this answer












                  If you want to pass an Icon to showConfirmDialog, you need to use the 6 argument overload:



                  JOptionPane.showConfirmDialog(
                  null,
                  velden,
                  "Spelers vergelijken",
                  JOptionPane.OK_CANCEL_OPTION,
                  JOptionPane.PLAIN_MESSAGE, // Add this argument
                  icon);


                  I've used PLAIN_MESSAGE in this example, but you can use any one of ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE as specified in the API documentation.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 21:38









                  Sean Bright

                  91.5k13112127




                  91.5k13112127






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401839%2fwhy-does-this-code-gives-me-the-error-imageicon-cannot-be-converted-to-int%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      Refactoring coordinates for Minecraft Pi buildings written in Python