Re: Setting Opaque false on JComboBox
- From: "Michael Dunn" <m_odunn@xxxxxxxxx>
- Date: 27 Feb 2006 13:25:58 -0800
try this for all but the drop-down
import javax.swing.*;
import java.awt.*;
class Testing extends JFrame
{
JComboBox cbo = new JComboBox(new String[]{"London","Madrid","New
York","Rome","Sydney"});
public Testing()
{
setSize(150,75);
setLocation(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jp = new JPanel();
jp.setBackground(Color.RED);
cbo.setEditable(true);
cbo.getEditor().getEditorComponent().setFocusable(false);//remove
for editable
cbo.setOpaque(false);
makeTransparent(cbo.getComponents());
jp.add(cbo);
getContentPane().add(jp);
}
public void makeTransparent(Component[] comp)
{
for(int x = 0; x < comp.length; x++)
{
if(comp[x] instanceof javax.swing.plaf.metal.MetalComboBoxButton)
{
((javax.swing.plaf.metal.MetalComboBoxButton)comp[x]).setOpaque(false);
((javax.swing.plaf.metal.MetalComboBoxButton)comp[x]).setBorder(null);
}
else if(comp[x] instanceof JTextField)
{
((JTextField)comp[x]).setOpaque(false);
((JTextField)comp[x]).setBorder(null);
}
}
}
public static void main(String args[]){new
Testing().setVisible(true);}
}
.
- References:
- Setting Opaque false on JComboBox
- From: jackroofman
- Setting Opaque false on JComboBox
- Prev by Date: Setting Opaque false on JComboBox
- Next by Date: jinternalpane freakiness
- Previous by thread: Setting Opaque false on JComboBox
- Next by thread: jinternalpane freakiness
- Index(es):