Anyone
I am new to Swing and Java GUI, but not Java, however far from an expert. I want to add an image as background in a class that extends a class that extends JFrame. Beforehand this class contains a couple of JLabels (Sliders etc), nothing complex, and is working fine. It will however be enhanced with "dynamic" functonality, i.e., I must prevent that the whole background image is constantly updated. Further, I want the background to be autonomous; fire and forget, like setting the background of an excel spreadsheet, still having full functionality of the spreadsheet.
Using the following code, I am able to display the image properly as a background image:
However, as soon as I start adding the other functionality, i.e. the other JLabels in a GridLayout, then the GUI update goes awry, only updating the part of the background image that is "beneath" the other JLabels. In other words, the code above is interacting with the rest of the code. This is exactly what I would like to avoid. THis happens: The rest of the background image, having a area/size that is larger than the GridLayout, is never shown at all, ie there is a clipping effect.
Q: Is there a simple way to define a background image to a JFrame, via JLAbel or whatever, but in such a way that it will be always automatically updated "according to good coding practice". Something like this: MyJFrame.setBackgroundImage ( image, FREEZE). With FREEZE I mean to indicate that the image is in no need of update by itself.
I see in the tutorials that I may use JLayeredPane, but isn't there a simpler way ?? Many thanks for anything that may help me further on, be it general guidance, pointer to interesting javadocs, principal code snippets, ... I am really a bit stuck after several days of investigations.
ch