I'm searching a way for use a 9-patch file as background for javax.swing.JPanel. So that the background image automatically resizes itself when the dimensions of the JPanel change.
Is it possible? Or I have to create all the pieces of the image and manually resize some of them when the listener triggers (like in the piece of code that follows)?
public class JPanelWithNinePatchBackground extends JPanel {
{
/* Define all parts of the background like BufferedImage */
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
// Resize images . . .
JPanelWithBackground.this.repaint();
}
});
/* . . . */
}