public class DesktopPaneImage extends JDesktopPane { private static final long serialVersionUID = -6350324456764768311L; private Image image; public DesktopPaneImage(Image image) { this.image = image; } @Override public void paintComponent(Graphics g){ if(image!=null){ Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.drawImage(image, 0, 0, getWidth(), getHeight(), null); } } }
@Override public void paintComponent(Graphics g){ g.drawImage(image, 0, 0, getWidth(), getHeight(), null); }
Image image = Toolkit.getDefaultToolkit().getImage("images_icones/IMM.PNG");
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionImageIO.read(getClass().getResource("IMM.PNG")
class DesktopPaneImage extends JDesktopPane { private static final long serialVersionUID = -6350324456764768311L; private Image image; public DesktopPaneImage(Image image) { this.image = image; } //g.drawImage(image, 0, 0, getWidth(), getHeight(), null); @Override public void paintComponent(Graphics g){ if(image!=null){ Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.drawImage(image, 0, 0,getWidth(), getHeight(), null); setOpaque(true); repaint(); } } }
public class my_ihm_2 extends JFrame { Image image = Toolkit.getDefaultToolkit().getImage("images_icones/IMM.PNG"); private final DesktopPaneImage desktopPane; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { try{ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch(Exception e){} my_ihm_2 frame = new my_ihm_2(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public my_ihm_2() { desktopPane = new DesktopPaneImage(image); desktopPane.setBounds(0, 23, 936, 519); getContentPane().add(desktopPane); // et la les autres choses ......................
my_ihm_2 frame = new my_ihm_2(); frame.setVisible(true);
je n'utilise pas des layouts pour faciliter le faite de placer les composants dans la fenetre librement