#noobie here, how do I align a background image with a JPanel?

1 messages · Page 1 of 1 (latest)

broken pulsarBOT
#

This post has been reserved for your question.

Hey @cursive drift! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

pastel pebble
#

The paintComponent method is defined in every class that extends the JComponent class. For this method to work with your class background. The class would need to extend JComponent or a class that extends JComponent (for example JPanel).

#

so therefore you need to override the paintComponent method of the JLabel.

#

I do think that you shouldn't mindlessly copy code but actually read up on some key concepts to write the code yourself.

#

a few things to note:

  1. By Convention java classes should start with an UpperCase letter and the name should correlate to the actual usecase of the class.
  2. The variable label is not used.
  3. frame.setVisible(true) should be the last step, after you added all other components to the frame.
  4. Your class currently extends JFrame. However currently you aren't actually using the superclass at all.