Created
December 23, 2013 08:06
-
-
Save resarahadian/8093301 to your computer and use it in GitHub Desktop.
Membuat ComboBox Transparan
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
import javax.swing.JPanel; | |
import java.awt.Color; | |
import java.awt.Graphics; | |
import java.awt.Graphics2D; | |
@SuppressWarnings("serial") | |
public class ClPanelTransparant extends JPanel | |
{ | |
private Color clr; | |
public ClPanelTransparant() | |
{ | |
setOpaque(false); | |
clr = new Color(getBackground().getRed(), getBackground().getRed(), getBackground().getGreen(),50); | |
} | |
public void setBackground(Color bg) | |
{ | |
super.setBackground(bg); | |
clr = new Color(getBackground().getRed(), getBackground().getRed(), getBackground().getGreen(),50); | |
repaint(); | |
} | |
protected void paintComponent(Graphics graph) | |
{ | |
super.paintComponent(graph); | |
Graphics2D g2d = (Graphics2D) graph.create(); | |
g2d.setColor(clr); | |
g2d.fillRect(0, 0, getWidth(), getHeight()); | |
g2d.dispose(); | |
} | |
} |
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
import java.awt.Component; | |
import java.awt.EventQueue; | |
import javax.swing.DefaultListCellRenderer; | |
import javax.swing.JComponent; | |
import javax.swing.JFrame; | |
import javax.swing.JList; | |
import javax.swing.JPanel; | |
import javax.swing.border.EmptyBorder; | |
import javax.swing.JComboBox; | |
import javax.swing.DefaultComboBoxModel; | |
import javax.swing.JLabel; | |
import javax.swing.ImageIcon; | |
import javax.swing.border.TitledBorder; | |
import java.awt.Color; | |
import javax.swing.JTextField; | |
import javax.swing.JButton; | |
import javax.swing.SwingConstants; | |
import java.awt.Font; | |
@SuppressWarnings("serial") | |
public class frameTransparanCombo extends JFrame { | |
private JPanel contentPane; | |
@SuppressWarnings("rawtypes") | |
private JComboBox cbJenis; | |
private JLabel lblWall; | |
private JPanel panel; | |
private JLabel lblId; | |
private JTextField txtID; | |
private JTextField txtNama; | |
private JLabel lblJenis; | |
private JLabel lblModel; | |
private JTextField txtModel; | |
private JButton btnSimpan; | |
private JButton btnUbah; | |
private JButton btnHapus; | |
private JLabel lblIcon; | |
/** | |
* Create the frame. | |
*/ | |
@SuppressWarnings({ "rawtypes", "unchecked" }) | |
public frameTransparanCombo() | |
{ | |
setTitle("Transparan ComboBox"); | |
setResizable(false); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setBounds(100, 100, 602, 404); | |
contentPane = new JPanel(); | |
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); | |
setContentPane(contentPane); | |
contentPane.setLayout(null); | |
panel = new ClPanelTransparant(); | |
panel.setBorder(new TitledBorder(null, "Data Komputer", TitledBorder.RIGHT, TitledBorder.TOP, null, new Color(255, 255, 255))); | |
panel.setBounds(29, 12, 414, 238); | |
contentPane.add(panel); | |
panel.setLayout(null); | |
lblId = new JLabel("ID : "); | |
lblId.setFont(new Font("Comic Sans MS", Font.BOLD, 12)); | |
lblId.setForeground(new Color(255, 204, 153)); | |
lblId.setBounds(12, 12, 70, 15); | |
panel.add(lblId); | |
txtID = new JTextField(); | |
txtID.setBounds(116, 10, 114, 19); | |
panel.add(txtID); | |
txtID.setColumns(10); | |
JLabel lblNama = new JLabel("Nama : "); | |
lblNama.setFont(new Font("Comic Sans MS", Font.BOLD, 12)); | |
lblNama.setForeground(new Color(255, 204, 153)); | |
lblNama.setBounds(12, 50, 70, 15); | |
panel.add(lblNama); | |
txtNama = new JTextField(); | |
txtNama.setBounds(116, 48, 269, 19); | |
panel.add(txtNama); | |
txtNama.setColumns(10); | |
lblJenis = new JLabel("Jenis : "); | |
lblJenis.setFont(new Font("Comic Sans MS", Font.BOLD, 12)); | |
lblJenis.setForeground(new Color(255, 204, 153)); | |
lblJenis.setBounds(12, 94, 70, 15); | |
panel.add(lblJenis); | |
cbJenis = new JComboBox(); | |
cbJenis.setBounds(116, 89, 162, 24); | |
panel.add(cbJenis); | |
cbJenis.setModel(new DefaultComboBoxModel(new String[] {"== Pilih ==", "Motherboard", "Mouse", "Keyboard"})); | |
cbJenis.setOpaque(false); | |
cbJenis.setRenderer(new DefaultListCellRenderer(){ | |
@Override | |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { | |
JComponent comp = (JComponent)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); | |
comp.setOpaque(false); | |
return comp; | |
}}); | |
lblModel = new JLabel("Model : "); | |
lblModel.setFont(new Font("Comic Sans MS", Font.BOLD, 12)); | |
lblModel.setForeground(new Color(255, 204, 153)); | |
lblModel.setBounds(12, 141, 70, 15); | |
panel.add(lblModel); | |
txtModel = new JTextField(); | |
txtModel.setBounds(116, 139, 114, 19); | |
panel.add(txtModel); | |
txtModel.setColumns(10); | |
btnSimpan = new ClButtonTransparant("Simpan"); | |
btnSimpan.setVerticalTextPosition(SwingConstants.BOTTOM); | |
btnSimpan.setHorizontalTextPosition(SwingConstants.CENTER); | |
btnSimpan.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingJava/src/TransparanComboBox/Simpan.png")); | |
btnSimpan.setBounds(471, 12, 117, 53); | |
contentPane.add(btnSimpan); | |
btnUbah = new ClButtonTransparant("Ubah"); | |
btnUbah.setVerticalTextPosition(SwingConstants.BOTTOM); | |
btnUbah.setHorizontalTextPosition(SwingConstants.CENTER); | |
btnUbah.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingJava/src/TransparanComboBox/Ubah.png")); | |
btnUbah.setBounds(471, 96, 117, 53); | |
contentPane.add(btnUbah); | |
btnHapus = new ClButtonTransparant("Hapus"); | |
btnHapus.setVerticalTextPosition(SwingConstants.BOTTOM); | |
btnHapus.setHorizontalTextPosition(SwingConstants.CENTER); | |
btnHapus.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingJava/src/TransparanComboBox/Hapus.png")); | |
btnHapus.setBounds(471, 184, 117, 53); | |
contentPane.add(btnHapus); | |
lblIcon = new JLabel(""); | |
lblIcon.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingJava/src/TransparanComboBox/icon.png")); | |
lblIcon.setBounds(455, 241, 133, 137); | |
contentPane.add(lblIcon); | |
lblWall = new JLabel(""); | |
lblWall.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingJava/src/TransparanComboBox/wall.jpg")); | |
lblWall.setBounds(0, -11, 600, 389); | |
contentPane.add(lblWall); | |
setLocationRelativeTo(null); | |
} | |
/** | |
* Launch the application. | |
*/ | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
try { | |
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); | |
frameTransparanCombo frame = new frameTransparanCombo(); | |
frame.setVisible(true); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment