I have a code that is working only in showing a JLabel
icon on a JPanel
in case of printing the label in a showMessageDialog
before adding the label to the JPanel
and then revalidate and repaint. If I removed the message dialog, it wouldn't be viewed on the panel, what does that mean?
Is it that the message dialog does a step that i should do in some missing statement(s)?
(Note: jPanel4
is contained by jPanel1
)
This is the code, which I use:
BufferedImage workerImage = ImageIO.read(workerImageFile);
ImageIcon icon = new ImageIcon(workerImage.getScaledInstance(jPanel4.getWidth(), jPanel4.getHeight(), BufferedImage.SCALE_SMOOTH));
workerImageLabel = new JLabel("", icon, JLabel.CENTER);
JOptionPane.showMessageDialog(null, workerImageLabel);
if(jPanel4.getComponentCount() == 0)
{
jPanel4.add(workerImageLabel, BorderLayout.CENTER );
jPanel1.revalidate();
jPanel1.repaint();
}else
{
jPanel4.remove(0);
jPanel4.add(workerImageLabel, BorderLayout.CENTER );
jPanel1.revalidate();
jPanel1.repaint();
}