Last active
April 19, 2024 12:49
-
-
Save hexvalid/423fa3e60328c4be0513 to your computer and use it in GitHub Desktop.
NetBeans - Set background jPanel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jPanel1 = new javax.swing.JPanel(){ | |
| @Override | |
| public void paintComponent(Graphics g) | |
| { | |
| g.drawImage(src, 0, 0, null); | |
| } | |
| }; | |
| // Code of sub-components and layout - not shown here | |
| add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 400, 300)); | |
| //Aaand Image: | |
| try { | |
| src = ImageIO.read(new File("splash.png")); | |
| } catch (IOException ex) { | |
| Logger.getLogger(Boot.class.getName()).log(Level.SEVERE, null, ex); | |
| } | |
| /////////////////////////////////FULL CODE:////// | |
| package taban; | |
| import java.awt.Frame; | |
| import java.awt.Graphics; | |
| import java.awt.Image; | |
| import java.awt.Toolkit; | |
| import javax.swing.ImageIcon; | |
| /** | |
| * | |
| * @author erkanmdr | |
| */ | |
| public class Boot extends java.awt.Frame { | |
| Image src; | |
| /** | |
| * Creates new form Boot | |
| */ | |
| public Boot() { | |
| src = Toolkit.getDefaultToolkit().createImage("/home/erkanmdr/splash.png"); | |
| initComponents(); | |
| } | |
| /** | |
| * This method is called from within the constructor to initialize the form. | |
| * WARNING: Do NOT modify this code. The content of this method is always | |
| * regenerated by the Form Editor. | |
| */ | |
| // <editor-fold defaultstate="collapsed" desc="Generated Code"> | |
| private void initComponents() { | |
| jPanel1 = new javax.swing.JPanel(){ | |
| @Override | |
| public void paintComponent(Graphics g) | |
| { | |
| g.drawImage(src, 0, 0, null); | |
| } | |
| }; | |
| setUndecorated(true); | |
| setPreferredSize(new java.awt.Dimension(400, 300)); | |
| setResizable(false); | |
| setSize(new java.awt.Dimension(400, 300)); | |
| addWindowListener(new java.awt.event.WindowAdapter() { | |
| public void windowClosing(java.awt.event.WindowEvent evt) { | |
| exitForm(evt); | |
| } | |
| }); | |
| setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); | |
| add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 400, 300)); | |
| pack(); | |
| setLocationRelativeTo(null); | |
| }// </editor-fold> | |
| /** | |
| * Exit the Application | |
| */ | |
| private void exitForm(java.awt.event.WindowEvent evt) { | |
| System.exit(0); | |
| } | |
| /** | |
| * @param args the command line arguments | |
| */ | |
| public static void main(String args[]) { | |
| java.awt.EventQueue.invokeLater(new Runnable() { | |
| public void run() { | |
| Frame f = new Boot(); | |
| f.setVisible(true); | |
| // this.add(kanvas); | |
| } | |
| }); | |
| } | |
| // Variables declaration - do not modify | |
| private javax.swing.JPanel jPanel1; | |
| // End of variables declaration | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment