After a couple of hours Playing around with NetBeans after reading and watching couple of tutorials I have found, I finally got a simple solution...
Here is the code:
package testPack;
import java.awt.Color;
import javax.swing.*;
import java.awt.Dimension;
/**
*
* @author Karyuu Ouji
*/
public class TestPanel extends javax.swing.JPanel {
/**
* Creates new form TestPanel
*/
public TestPanel() {
initComponents();
this.setPreferredSize(new Dimension(704,182));
this.setOpaque(false);
this.setDoubleBuffered(true);
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setLayout(null);
jButton1.setText("Close");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(java.awt.event.MouseEvent evt) {
jButton1MouseReleased(evt);
}
});
add(jButton1);
jButton1.setBounds(593, 0, 110, 23);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/testPack/sao.png"))); // NOI18N
jLabel1.setText("jLabel1");
add(jLabel1);
jLabel1.setBounds(0, 0, 704, 180);
}// </editor-fold>
private void jButton1MouseReleased(java.awt.event.MouseEvent evt) {
System.exit(0);
}
public static void main(String[] args) {
JFrame frmMain = new JFrame();
frmMain.setUndecorated(true);
frmMain.setBackground(new Color(0,0,0,0));
frmMain.add(new TestPanel());
frmMain.pack();
frmMain.setLocationRelativeTo(null);
frmMain.setVisible(true);
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
Note: Most of the code are generated by NetBeans
All I did was add a JLabel
from the component pallet and set the size of the JPanel
and JLabel
the same as the image size.
Then I put on the image in the JLabel
via the Icon
property.
Setting Icon/Image
And here is what it looks like when I run the app.
Running
I hope this will help someone like me in the future... :)