0

I am working on a project basically a log in screen, all is well but one icon is failing to show up, the code is as follows:

private JLabel lblIconSilhouette = new JLabel(); 
private Icon IconSilhouette = new ImageIcon("C:\\Users\\Bryan\\Documents\\ModSimIcons\\silhouette.png");
panelRight.setLayout(new GridBagLayout());
        panelRight.setBackground(new Color(164,74,74,255));
        panelRight.setPreferredSize(new Dimension(screenWidth/2,screenHeight));
        txtStudentNumber.setPreferredSize(new Dimension(150,25));
        txtPassword.setPreferredSize(new Dimension(150,25));
        btnEnter.setPreferredSize(new Dimension(100, 25));

        //this is the icon i have trouble displaying
        lblIconSilhouette.setIcon(IconSilhouette);
        lblIconSilhouette.setPreferredSize(new Dimension(400, 300));
        grid.gridx=1;
        grid.gridy=0;
        panelRight.add(lblIconSilhouette,grid);


        grid.gridx=1;
        grid.gridy=2;
        panelRight.add(txtStudentNumber,grid);
        grid.gridx=1;
        grid.gridy=3;
        panelRight.add(txtPassword,grid);
        grid.gridx=1;
        grid.gridy=4;
        panelRight.add(btnEnter,grid);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • The GridBagLayout is 0, 0 based, so what Swing component is located at gridx, gridy position 0, 0? Also, you should use ImageIO to read all your images before you even start constructing the GUI. – Gilbert Le Blanc Feb 13 '21 at 11:43
  • 1) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). E.G. The code in [this answer](https://stackoverflow.com/a/10862262/418556) hot links to an image embedded in [this question](https://stackoverflow.com/q/10861852/418556). – Andrew Thompson Mar 11 '21 at 00:24

0 Answers0