This is my code, it really finds the image, so this is not my concern, I am worried about how to make this image the background of the panel. I try to work with graphics, but I do not work, any ideas? you are welcome??
try { java.net.URL imgURL = MAINWINDOW.class.getResource(imagen); Image imgFondo = javax.imageio.ImageIO.read(imgURL); if (imgFondo != null) { Graphics grafica=null; grafica.drawImage(imgFondo, 0, 0, this); panel.paintComponents(grafica); } else { System.err.println("Couldn't find file: " + imagen); } } catch...
. grafica null, . , , NullPointerException. Graphics , , . Swing, paintComponent , :
grafica
null
NullPointerException
paintComponent
public void paintComponent(Graphics grafica) { grafica.drawImage(imgFondo, 0, 0, this); }
, , . , imgFondo , paintComponent.
imgFondo
, JLabel, , .
, , - - .
. .
Swing Custom Painting.
Source: https://habr.com/ru/post/1747720/More articles:ASP.NET: What is the best way to check the three drop-down windows that are used to select a date (month, day, year)? - validationI use the correct content type and headers. Why FireFox Saves Zip Files Without Extensions - typesMicrosoft Sync Framework - How to redraw a table (or the entire area) after changing a schema? - synchronizationAdding and adding XML files with Clojure - xmlWeb application caching files locally (for efficiency) - web-applicationsWhat can I do with Seed? - javascriptGet the text box in C # - c #Rails 2.3: How to turn this SQL statement into named_scope - ruby | fooobar.comregex for string in c - stringCentering in IE5 / 6/7/8 and FF - htmlAll Articles