How to make JComboBoxes transparent

For some reason "setOpaque(false)" doesn't seem to work for JComboBoxes. I'm using java 1.4
Below is some code. If you compile and run it you should get a window with a button and a combo box, the button is transparent, the combo box is not.
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Area;
* test transparent swing components
class TransTest
public static void main(String args[])
     JFrame theFrame = new JFrame("transparency test");
     JComponent contentPane = new JComponent()
          public void paint(Graphics g)
          Graphics2D g2 = (Graphics2D)g;
          Area s = new Area((Shape)new Rectangle(0, 0, getWidth(), getHeight()));
          g2.setPaint(new GradientPaint(0f, 0f, Color.GRAY, 150f, 100f, Color.WHITE, true));
          g2.fill(s);
          super.paintChildren(g);
     theFrame.setContentPane(contentPane);
     theFrame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     JButton button = new JButton("button");
     button.setOpaque(false);          // this works
     JComboBox combo = new JComboBox();
     combo.addItem("combo");
     combo.setOpaque(false);               // this doesn't seem to work
     JPanel pnl = new JPanel();
     pnl.setOpaque(false);
     pnl.add(button);
     pnl.add(combo);
     contentPane.setLayout(new BorderLayout());
     contentPane.add(pnl, BorderLayout.CENTER);
     theFrame.pack();
     theFrame.setVisible(true);

Try setOpaque(true) and setBackground(new Color(r,g,b,a)) where r, g and b are respectively the values of red, green and blue and a the alpha value (0 means totaly transparent, 255 totaly opaque). Sometimes a component should be opaque with a transparent background to make the transcparency works.
But I have to ask you a question : have you bugs with the display ? Indeed, I made an app that doesn't use a gradient paint like you, but the JFrame have a ContentPane that display a picture. I made every JComponent transparent in order to see the background picture. The display is very dirty with JButton, JTextArea, JTextField and JList. Indeed, when moving cursor over JButton, the JButton displays the top lecft corner of the JFrame instead of the underlaying part of the picture as expected with transparency. With JTextField and JTextArea, when typing text the same problem occured. With JList, the problem appear when scrolling. only a full update(Graphics g) can clean the display, that is I must call it with every mouseMoved, mouseClicked, etc. events. The problem appears only with JDK > 1.2.2 (JDK1.3 and later)

Similar Messages

  • How to make a transparent Frame

    How to make a transparent Frame , just like the .NET Frame ??

    Maybe searching the forum using the keywords "+transparent +frame" or "+transparent +jframe" would be a good place to start.

  • How to make treetable transparent

    hi,
    Does anyone have idea how to make the treetable transparent so that the background image can be shown?
    Pls provide sample code if possible,thanks!

    I don't know if I can come up with some code example
    for you since I don't know what treetable your are
    using... but... Transparency is always going to relate
    to the whether your components are opaque or not.
    Opaque = Not Transparent, so setting opaque = false
    will hopefully make your table transparent. You may
    need to do this on your CellRenderer's as well.
    Hope this helps,
    Josh Castagno
    http://www.jdc-software.com
    hi,
    i am using JTreeTable provided fron Sun swing connection article,by Scott Violet and Kathy Walrath.
    The situation i am facng now is jtree able to be transparent, but jtable still using it default background.
    Below are excerpt from sample, setOpaque(false) to jtable seem doesn't take effect.
    As i an newbie to swing,kindly point out where part shd i modified on the code. Thz!
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    import java.util.EventObject;
    * This example shows how to create a simple JTreeTable component,
    * by using a JTree as a renderer (and editor) for the cells in a
    * particular column in the JTable.
    * @version 1.2 10/27/98
    * @author Philip Milne
    * @author Scott Violet
    public class JTreeTable extends JTable {
    /** A subclass of JTree. */
    protected TreeTableCellRenderer tree;
    public JTreeTable(TreeTableModel treeTableModel) {
         super();
         // Creates the tree. It will be used as a renderer and editor.
         tree = new TreeTableCellRenderer(treeTableModel);
         // Installs a tableModel representing the visible rows in the tree.
         super.setModel(new TreeTableModelAdapter(treeTableModel, tree));
         // Forces the JTable and JTree to share their row selection models.
         ListToTreeSelectionModelWrapper selectionWrapper = new
         ListToTreeSelectionModelWrapper();
         tree.setSelectionModel(selectionWrapper);
         setSelectionModel(selectionWrapper.getListSelectionModel());
         // Installs the tree editor renderer and editor.
         setDefaultRenderer(TreeTableModel.class, tree);
         setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor());
         // No grid.
         setShowGrid(false);
    //added
    setOpaque(false);
         // No intercell spacing
         setIntercellSpacing(new Dimension(0, 0));     
         // And update the height of the trees row to match that of
         // the table.
         if (tree.getRowHeight() < 1) {
         // Metal looks better like this.
         setRowHeight(20);
    * Overridden to message super and forward the method to the tree.
    * Since the tree is not actually in the component hierarchy it will
    * never receive this unless we forward it in this manner.
    public void updateUI() {
         super.updateUI();
         if(tree != null) {
         tree.updateUI();
         // Do this so that the editor is referencing the current renderer
         // from the tree. The renderer can potentially change each time
         // laf changes.
         setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor());
         // Use the tree's default foreground and background colors in the
         // table.
    LookAndFeel.installColorsAndFont(this, "Tree.background",
    "Tree.foreground", "Tree.font");
    * Workaround for BasicTableUI anomaly. Make sure the UI never tries to
    * resize the editor. The UI currently uses different techniques to
    * paint the renderers and editors; overriding setBounds() below
    * is not the right thing to do for an editor. Returning -1 for the
    * editing row in this case, ensures the editor is never painted.
    public int getEditingRow() {
    return (getColumnClass(editingColumn) == TreeTableModel.class) ? -1 :
         editingRow;
    * Returns the actual row that is editing as <code>getEditingRow</code>
    * will always return -1.
    private int realEditingRow() {
         return editingRow;
    * This is overridden to invoke super's implementation, and then,
    * if the receiver is editing a Tree column, the editor's bounds is
    * reset. The reason we have to do this is because JTable doesn't
    * think the table is being edited, as <code>getEditingRow</code> returns
    * -1, and therefore doesn't automatically resize the editor for us.
    public void sizeColumnsToFit(int resizingColumn) {
         super.sizeColumnsToFit(resizingColumn);
         if (getEditingColumn() != -1 && getColumnClass(editingColumn) ==
         TreeTableModel.class) {
         Rectangle cellRect = getCellRect(realEditingRow(),
                             getEditingColumn(), false);
    Component component = getEditorComponent();
         component.setBounds(cellRect);
    component.validate();
    * Overridden to pass the new rowHeight to the tree.
    public void setRowHeight(int rowHeight) {
    super.setRowHeight(rowHeight);
         if (tree != null && tree.getRowHeight() != rowHeight) {
    tree.setRowHeight(getRowHeight());
    * Returns the tree that is being shared between the model.
    public JTree getTree() {
         return tree;
    * Overridden to invoke repaint for the particular location if
    * the column contains the tree. This is done as the tree editor does
    * not fill the bounds of the cell, we need the renderer to paint
    * the tree in the background, and then draw the editor over it.
    public boolean editCellAt(int row, int column, EventObject e){
         boolean retValue = super.editCellAt(row, column, e);
         if (retValue && getColumnClass(column) == TreeTableModel.class) {
         repaint(getCellRect(row, column, false));
         return retValue;
    * A TreeCellRenderer that displays a JTree.
    public class TreeTableCellRenderer extends JTree implements
         TableCellRenderer {
         /** Last table/tree row asked to renderer. */
         protected int visibleRow;
         /** Border to draw around the tree, if this is non-null, it will
         * be painted. */
         protected Border highlightBorder;
         public TreeTableCellRenderer(TreeModel model) {
         super(model);
         * updateUI is overridden to set the colors of the Tree's renderer
         * to match that of the table.
         public void updateUI() {
         super.updateUI();
         // Make the tree's cell renderer use the table's cell selection
         // colors.
         TreeCellRenderer tcr = getCellRenderer();
         if (tcr instanceof DefaultTreeCellRenderer) {
              DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer)tcr);
              // For 1.1 uncomment this, 1.2 has a bug that will cause an
              // exception to be thrown if the border selection color is
              // null.
              // dtcr.setBorderSelectionColor(null);
              dtcr.setTextSelectionColor(UIManager.getColor
                             ("Table.selectionForeground"));
              dtcr.setBackgroundSelectionColor(UIManager.getColor
                                  ("Table.selectionBackground"));
         * Sets the row height of the tree, and forwards the row height to
         * the table.
         public void setRowHeight(int rowHeight) {
         if (rowHeight > 0) {
              super.setRowHeight(rowHeight);
              if (JTreeTable.this != null &&
              JTreeTable.this.getRowHeight() != rowHeight) {
              JTreeTable.this.setRowHeight(getRowHeight());
         * This is overridden to set the height to match that of the JTable.
         public void setBounds(int x, int y, int w, int h) {
         super.setBounds(x, 0, w, JTreeTable.this.getHeight());
         * Sublcassed to translate the graphics such that the last visible
         * row will be drawn at 0,0.
         public void paint(Graphics g) {
         g.translate(0, -visibleRow * getRowHeight());
         super.paint(g);
         // Draw the Table border if we have focus.
         if (highlightBorder != null) {
              highlightBorder.paintBorder(this, g, 0, visibleRow *
                             getRowHeight(), getWidth(),
                             getRowHeight());
         * TreeCellRenderer method. Overridden to update the visible row.
         public Component getTableCellRendererComponent(JTable table,
                                  Object value,
                                  boolean isSelected,
                                  boolean hasFocus,
                                  int row, int column) {
         Color background;
         Color foreground;
         if(isSelected) {
              background = table.getSelectionBackground();
              foreground = table.getSelectionForeground();
         else {
              background = table.getBackground();
              foreground = table.getForeground();
         highlightBorder = null;
         if (realEditingRow() == row && getEditingColumn() == column) {
              background = UIManager.getColor("Table.focusCellBackground");
              foreground = UIManager.getColor("Table.focusCellForeground");
         else if (hasFocus) {
              highlightBorder = UIManager.getBorder
              ("Table.focusCellHighlightBorder");
              if (isCellEditable(row, column)) {
              background = UIManager.getColor
                   ("Table.focusCellBackground");
              foreground = UIManager.getColor
                   ("Table.focusCellForeground");
         visibleRow = row;
         setBackground(background);
         TreeCellRenderer tcr = getCellRenderer();
         if (tcr instanceof DefaultTreeCellRenderer) {
              DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer)tcr);
              if (isSelected) {
              dtcr.setTextSelectionColor(foreground);
              dtcr.setBackgroundSelectionColor(background);
              else {
              dtcr.setTextNonSelectionColor(foreground);
              dtcr.setBackgroundNonSelectionColor(background);
         return this;
    * An editor that can be used to edit the tree column. This extends
    * DefaultCellEditor and uses a JTextField (actually, TreeTableTextField)
    * to perform the actual editing.
    * <p>To support editing of the tree column we can not make the tree
    * editable. The reason this doesn't work is that you can not use
    * the same component for editing and renderering. The table may have
    * the need to paint cells, while a cell is being edited. If the same
    * component were used for the rendering and editing the component would
    * be moved around, and the contents would change. When editing, this
    * is undesirable, the contents of the text field must stay the same,
    * including the caret blinking, and selections persisting. For this
    * reason the editing is done via a TableCellEditor.
    * <p>Another interesting thing to be aware of is how tree positions
    * its render and editor. The render/editor is responsible for drawing the
    * icon indicating the type of node (leaf, branch...). The tree is
    * responsible for drawing any other indicators, perhaps an additional
    * +/- sign, or lines connecting the various nodes. So, the renderer
    * is positioned based on depth. On the other hand, table always makes
    * its editor fill the contents of the cell. To get the allusion
    * that the table cell editor is part of the tree, we don't want the
    * table cell editor to fill the cell bounds. We want it to be placed
    * in the same manner as tree places it editor, and have table message
    * the tree to paint any decorations the tree wants. Then, we would
    * only have to worry about the editing part. The approach taken
    * here is to determine where tree would place the editor, and to override
    * the <code>reshape</code> method in the JTextField component to
    * nudge the textfield to the location tree would place it. Since
    * JTreeTable will paint the tree behind the editor everything should
    * just work. So, that is what we are doing here. Determining of
    * the icon position will only work if the TreeCellRenderer is
    * an instance of DefaultTreeCellRenderer. If you need custom
    * TreeCellRenderers, that don't descend from DefaultTreeCellRenderer,
    * and you want to support editing in JTreeTable, you will have
    * to do something similiar.
    public class TreeTableCellEditor extends DefaultCellEditor {
         public TreeTableCellEditor() {
         super(new TreeTableTextField());
         * Overridden to determine an offset that tree would place the
         * editor at. The offset is determined from the
         * <code>getRowBounds</code> JTree method, and additionally
         * from the icon DefaultTreeCellRenderer will use.
         * <p>The offset is then set on the TreeTableTextField component
         * created in the constructor, and returned.
         public Component getTableCellEditorComponent(JTable table,
                                  Object value,
                                  boolean isSelected,
                                  int r, int c) {
         Component component = super.getTableCellEditorComponent
              (table, value, isSelected, r, c);
         JTree t = getTree();
         boolean rv = t.isRootVisible();
         int offsetRow = rv ? r : r - 1;
         Rectangle bounds = t.getRowBounds(offsetRow);
         int offset = bounds.x;
         TreeCellRenderer tcr = t.getCellRenderer();
         if (tcr instanceof DefaultTreeCellRenderer) {
              Object node = t.getPathForRow(offsetRow).
              getLastPathComponent();
              Icon icon;
              if (t.getModel().isLeaf(node))
              icon = ((DefaultTreeCellRenderer)tcr).getLeafIcon();
              else if (tree.isExpanded(offsetRow))
              icon = ((DefaultTreeCellRenderer)tcr).getOpenIcon();
              else
              icon = ((DefaultTreeCellRenderer)tcr).getClosedIcon();
              if (icon != null) {
              offset += ((DefaultTreeCellRenderer)tcr).getIconTextGap() +
                   icon.getIconWidth();
         ((TreeTableTextField)getComponent()).offset = offset;
         return component;
         * This is overridden to forward the event to the tree. This will
         * return true if the click count >= 3, or the event is null.
         public boolean isCellEditable(EventObject e) {
         if (e instanceof MouseEvent) {
              MouseEvent me = (MouseEvent)e;
              // If the modifiers are not 0 (or the left mouse button),
    // tree may try and toggle the selection, and table
    // will then try and toggle, resulting in the
    // selection remaining the same. To avoid this, we
    // only dispatch when the modifiers are 0 (or the left mouse
    // button).
              if (me.getModifiers() == 0 ||
    me.getModifiers() == InputEvent.BUTTON1_MASK) {
              for (int counter = getColumnCount() - 1; counter >= 0;
                   counter--) {
                   if (getColumnClass(counter) == TreeTableModel.class) {
                   MouseEvent newME = new MouseEvent
                   (JTreeTable.this.tree, me.getID(),
                        me.getWhen(), me.getModifiers(),
                        me.getX() - getCellRect(0, counter, true).x,
                        me.getY(), me.getClickCount(),
    me.isPopupTrigger());
                   JTreeTable.this.tree.dispatchEvent(newME);
                   break;
              if (me.getClickCount() >= 3) {
              return true;
              return false;
         if (e == null) {
              return true;
         return false;
    * Component used by TreeTableCellEditor. The only thing this does
    * is to override the <code>reshape</code> method, and to ALWAYS
    * make the x location be <code>offset</code>.
    static class TreeTableTextField extends JTextField {
         public int offset;
         public void reshape(int x, int y, int w, int h) {
         int newX = Math.max(x, offset);
         super.reshape(newX, y, w - (newX - x), h);
    * ListToTreeSelectionModelWrapper extends DefaultTreeSelectionModel
    * to listen for changes in the ListSelectionModel it maintains. Once
    * a change in the ListSelectionModel happens, the paths are updated
    * in the DefaultTreeSelectionModel.
    class ListToTreeSelectionModelWrapper extends DefaultTreeSelectionModel {
         /** Set to true when we are updating the ListSelectionModel. */
         protected boolean updatingListSelectionModel;
         public ListToTreeSelectionModelWrapper() {
         super();
         getListSelectionModel().addListSelectionListener
         (createListSelectionListener());
         * Returns the list selection model. ListToTreeSelectionModelWrapper
         * listens for changes to this model and updates the selected paths
         * accordingly.
         ListSelectionModel getListSelectionModel() {
         return listSelectionModel;
         * This is overridden to set <code>updatingListSelectionModel</code>
         * and message super. This is the only place DefaultTreeSelectionModel
         * alters the ListSelectionModel.
         public void resetRowSelection() {
         if(!updatingListSelectionModel) {
              updatingListSelectionModel = true;
              try {
              super.resetRowSelection();
              finally {
              updatingListSelectionModel = false;
         // Notice how we don't message super if
         // updatingListSelectionModel is true. If
         // updatingListSelectionModel is true, it implies the
         // ListSelectionModel has already been updated and the
         // paths are the only thing that needs to be updated.
         * Creates and returns an instance of ListSelectionHandler.
         protected ListSelectionListener createListSelectionListener() {
         return new ListSelectionHandler();
         * If <code>updatingListSelectionModel</code> is false, this will
         * reset the selected paths from the selected rows in the list
         * selection model.
         protected void updateSelectedPathsFromSelectedRows() {
         if(!updatingListSelectionModel) {
              updatingListSelectionModel = true;
              try {
              // This is way expensive, ListSelectionModel needs an
              // enumerator for iterating.
              int min = listSelectionModel.getMinSelectionIndex();
              int max = listSelectionModel.getMaxSelectionIndex();
              clearSelection();
              if(min != -1 && max != -1) {
                   for(int counter = min; counter <= max; counter++) {
                   if(listSelectionModel.isSelectedIndex(counter)) {
                        TreePath selPath = tree.getPathForRow
                        (counter);
                        if(selPath != null) {
                        addSelectionPath(selPath);
              finally {
              updatingListSelectionModel = false;
         * Class responsible for calling updateSelectedPathsFromSelectedRows
         * when the selection of the list changse.
         class ListSelectionHandler implements ListSelectionListener {
         public void valueChanged(ListSelectionEvent e) {
              updateSelectedPathsFromSelectedRows();

  • How to make jframe transparent?

    Hi
      some software's uses the monitor as a whiteboard to draw or to type text. How is this possible? I mean i thought that by making a  jframe (full screen) transparent we should be able to do this?   Is my understanding right? if so how to make the jframe transparent? when jframe is transparent will we be able to draw on it?

    Try this:
    public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
      @Override public void run() {
      JFrame f = new JFrame();
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setUndecorated(true);
      f.setBackground(new Color(0,0,0,0));
      f.setExtendedState(JFrame.MAXIMIZED_BOTH);
      f.add(new JComponent() {
      @Override protected void paintComponent(Graphics g) {
      g.setColor(Color.BLUE);
      ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.fillOval(0, 0, getWidth(), getHeight());
      f.setVisible(true);
    Message was edited by: 946128 in respose to PhHein's comment

  • Spherical Photo Gallery how to make a transparent background

    http://www.flashandmath.com/flashcs4/spheregallery/index.html
    http://www.flashandmath.com/flashcs4/spheregallery/spherical_gallery.zip
    I am pretty new to the world of flash, a flash newbie.
    Please check link above my question is related to making this sphere gallery.
    I am trying to make the background transparent, and i can , when i make it transparent
    the navigation for the sphere doesnt let me navigate throught the pictures.
    If you look at the code i made it transparent by removing the drawboard function or the fills in the function.
    As i said when i do this the navigation seems non functional.
    if download link does not work try the other at the top.

    Hi,
    Since you had written event handlers on 'board' and board is transparent (without drawBoard function), there will be no events triggered and navigation is not possible. Workaround is to create board with fill = minimum alpha value (0.01).
    board.graphics.beginFill(0x0, 0.01);
    Let me know if you need more information.
    Regards,
    Karthikeyan R.

  • How to make a transparent java applet?

    is it possible to make a transparent applet?

    No. But consider making the applet paint a background that matches (in colour and texture) the background of the web page in which it's being displayed.

  • How to make a transparent header?

    Hello everyone,
    Im a beginner in photoshop, so excuse me if this is not a very smart question.
    I did a bit of editing with the header on the site http://www.amazingplacelist.com but i want to make the header a little bit transparant.
    Is this possible and how do i achieve this/wich settings do i use in photoshop?
    thank you!

    Hi there
    It would be helpful if you could post a screenshot of your layers panel if that is possible. However, I've posted a few tips below on using opacity with layers.
    Below is the layers panel for my re-creation of your image. It may not look similar to your layers panel, but if you'd like, I can provide instructions for how I created my image. Essentially, I have a colored background layer, the island image with an opacity mask, and a basic text layer.
    To change the opacity of the island, click on the thumbnail of the image in your layers panel. In the top right area of the layers panel (shown below), there should be a slider labeled "Opacity". This will allow you to change the transparency of the image.
    Now, since you're using this image on a website, it will be helpful to use Photoshop's Save for Web function. Choose File > Save for Web... from the menu bar.
    This function will allow you to save images for use on the web, and will also allow you to preserve any transparency. Note that below I've selected PNG as my file type and checked the box for "Preserve transparency".
    I hope this helped you out, if you need additional explanations or instructions, please don't hesitate to ask
    Good luck!

  • How to make JComboBox display an item not in list?

    hi,
    i'd like a gui component which is basically a jcombobox that presents a list A,B,C,D.
    The combobox is paired with another gui component which allows choosing sets of items. A etc.. represent preselected sets of items, so the user can click on A and a particular set would be selected.
    My problem is what to have the JComboBox do when the user selects a set of items that is not in the preselected defaults list. It would be nice to have the JComboBox just say "Other" at the top or something, but I can't figure out a way of doing this without putting the String "Other" in the list of items..
    does anyone have any idea of how to approach this? (I looked at making the JComboBox editable but this seems a little complicated?)
    thanks,
    asjf

    Your best option and cleanest design is to have a
    dummy data item in your list for "none of the above". thanks for the reply - this is what I'm doing at the moment. The problem is that I'm expecting testers to legitimately complain that selecting "None of the above" doesn't do anything, and doesn't really make sense ( it could make a random selection :o) )
    i think i agree that adding functionality to do this "properly" is likely to be more work/pain than its worth..
    Only an editable combobox can display something not in the list.this might help - if I could block mouse clicks to the editable area, and write to it programmatically but think this is probably quite difficult (?)
    asjf

  • How to make jcombobox display all by itlself?

    Hello all -
    Is there a way to make a jcombobox object display its column of items implicitly?
    For example, suppose a program has a combobox filled up with names. And, suppose the first item says "toggle sort", which affects how the items are sorted in the combobox (eg, pressing it should cause the list to sort the displayed names based on first name, another press bases the sort on the last name...). The behavior I am aiming for is that when the user presses the "toggle sort" item, the combobox displays its items again awaiting further selection from the user (but not the first item). Know how to fire such an event?
    private void namesComboBoxActionPerformed(ActionEvent evt) {
       int selected = namesComboBox.getSelectedIndex();
       if (selected == 0) {
          // some code should result in the namesComboBox displaying its items again. What is it please?
    }

    Here is a simple code, I don't know if its the correct way to do this sort of thing but it works:
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Collections;
    import javax.swing.*;
    * Sorting Combobox....
    * @author talha
    public class ComboSort extends JFrame{
        ArrayList<ComboData> data;
        JComboBox combo;
        public ComboSort() {
            super("Combo Sorting");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            populateData();
            Collections.sort(data);
            // I don't know how much of the combobox model should be overridden!
            combo=new JComboBox(new DefaultComboBoxModel() {
                @Override
                public Object getElementAt(int index) {
                    return (index==0)?"Toggle Sort":data.get(index-1);
                @Override
                public int getSize() {
                    return data.size()+1;
                @Override
                public int getIndexOf(Object anObject) {
                    return (anObject instanceof String)?0:data.indexOf(anObject)+1;
            combo.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if(combo.getSelectedIndex()==0){
                        ComboData.toggleSort();
                        Collections.sort(data);
                        //edited to make the pop up visible....
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                combo.setPopupVisible(true);
            combo.setRenderer(new DefaultListCellRenderer() {
                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    Component renderer=super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                    if(value instanceof String){
                        renderer.setForeground(Color.BLUE);
                        renderer.setBackground(Color.YELLOW);
                    return renderer;
            // you can remove following....
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    combo.setSelectedIndex(0);
            getContentPane().setLayout(new FlowLayout());
            getContentPane().add(new JLabel("Heads of State:"));
            getContentPane().add(combo);
            setSize(300, 300);
            setLocationRelativeTo(null);
        private void populateData() {
            data=new ArrayList<ComboData>();
            data.add(new ComboData("Barak", "Obama"));
            data.add(new ComboData("Gordon", "Brown"));
            data.add(new ComboData("Nicolas", "Sarkozy"));
            data.add(new ComboData("Angela", "Merkel"));
            data.add(new ComboData("Wen", "Jiabao"));
            data.add(new ComboData("Taro", "Aso"));
            data.add(new ComboData("Manmohan", "Singh"));
            data.add(new ComboData("Asif", "Zardari"));
            data.add(new ComboData("Mahmoud", "Ahmedinejad"));
            data.add(new ComboData("Hugo", "Chavez"));
            data.add(new ComboData("Raul", "Castro"));
        public static void main(String args[]){
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new ComboSort().setVisible(true);
    class ComboData implements Comparable{
        String firstname;
        String lastname;
        static boolean sortFirstName;
        public ComboData(String firstname, String lastname) {
            this.firstname = firstname;
            this.lastname = lastname;
        @Override
        public String toString() {
            return firstname+" "+lastname;
        public static void toggleSort(){
            sortFirstName=!sortFirstName;
        public int compareTo(Object o) {
            ComboData other=(ComboData)o;
            if(sortFirstName)return firstname.compareTo(other.firstname);
            else return lastname.compareTo(other.lastname);
    }Thanks!
    Edit: Reread your original post and made few editions... but I still don't think that this is what you need (but now its much better) :-)
    Edited by: T.B.M on Apr 19, 2009 1:16 PM

  • How to make image transparent to background in Web Dynpro...

    Hi Experts,
    IN our web dynpro application, we need to have some fonts and sizes of texts to be displayed on the layout. Since web dynpro has limited options for the design and color of a Textview, we have decided to use the image instead.
    This image has exactly the same background color as that of web dynpro and is matching perfectly.
    But the problem is, it shows a border surrounding the image. We need to remove that border and make it completely transparent to the web dynpro background.
    I have tried different design options for Image element but it did not worked.
    Has anyone done this earlier..
    Regards,
    Anand

    Thanks Nitesh,
    I have downloaded the MIME image and it doesn't appear to have the border. This border is added by web dynpro application itself.
    Regards,
    Anand

  • How to make a transparent background in a PNG file

    I would like to make a PNG image with a transparent background instead of the white background. See this link for the image:
    http://www.drifterandthegypsy.com/wp-content/uploads/2012/11/lookatthebrightside_11.jpg
    I have a very old Photoshop program Photoshop 7.
    I tried clicking on Save for Web and selecting PNG-24 and checking the transparent box but it didnt work.

    Hi,
    Try something like the following:
    (click on the screenshots below for larger views)
    1. Select the Magic Wand and set the same settings in the tool options bar as shown below.
        Click on the white area outside the yellow circle with the magic wand tool.
    2. Go to Select>Modify>Expand and enter 1
    3. Go to Edit>Cut
    4. Go to Image>Trim and check Transparent Pixels
    5. Go to File>Save For Web and choose PNG-24 with Transparency checked

  • How to make a transparent text layer over a photo that scrolls?

    I looked through the Adobe Inspire Magazine, and found something really astonishing: the editor's added a text-over-photo effect multiple times throughout the magazine (See http://inspire.adobe.com/, october 2014. Has to be on the iPad to see the actual effect. "It's about the stories" by Dan Cowles features this effect).
    I was really baffled to see it, as it fits my current project perfectly. I'm building a book about a recent trip to Iceland, which will be released for the iPad in the nearest future. So far, I have used Adobe InDesign CC to create pretty much the entire book, since I know little to nothing about programming.
    My question is, how did they (he) do it?
    Is it possible to do for someone with pretty limited knowledge? If it is, how can I do it?
    Thanks a lot!

    Since Adobe Inspire is made using DPS, then you can do everything that it does.
    At the top of the help document, Digital Publishing Suite Help | Digital Publishing Suite Help, there are links to topics like Getting Started, Design and Layout, System Requirements, etc. Read them over to gain an overview. Also, download and review DPS Tips from the App Store.
    If you are using Creative Cloud 2014, you should already have DPS Tools available to you. DPS is supported for InDesign version 6 and greater. I have found DPS pretty straight forward to use following the information given in the documentation along with help from this forum and DPS Tips.

  • Guided Access (how to make areas transparent rather than gray?)

    I'm trying to use guided access so I can read while holding the iPad like a book = don't wish to have my thumbs changing the zoom and place I'm at in the trext...
    When I set up Guided access for this and mark off regions for my thumbs they show up as gray regions which is annoying. Is there a way to make them clear, or even better another solution for this problem as guided access seems rather flacky at times. Thanks

    Hi all,
    I've this quiestion too. My target is make it for eBook reader, such as (reading pdf). Or any 3rd parties apps can't do it? Thanks a lot.

  • How to make a transparent object fully opaque while keeping the same color appearance?

    for a single object in a document.
    I will greatly appreciate your help.

    Flatten transparency on a copy and take the color with the eyedropper? Any better way?

  • How to make a transparent background for logo

    I've tried creating a transparent backgound for a logo in Photoshop CS4 in numerous ways such as saving the file as a png and using the magic wand (text resolution was very poor) but neither worked. My logo has text and an image.
    Any ideas?
    Thanks.

    I saved the file as a png and the background was not transparent--that is, it retained the white background. Please see the attached image for the pgn settings. In additon to a low resolution web version, I need to save a high resolution version for print.

Maybe you are looking for

  • How to tell if nic card is working at 100mb or 10mb??

    hello, subject line says it all. also, what would be best way to migrate to the open workgroup suite from sbs6.5?? I'm running everything on one server. would like to add the blackberry server to the new system. need to run citrix as well (only runs

  • Product search is not working in other JSP inj b2c application

    hi, I had one requirement that we have to bring product search from header jsp(b2c/navigationbar.inc.jsp) to CategoriesB2C.inc.jsp. i had copied all related code from last jsp.but search is not working. i had modified only jsp.just guide me do we hav

  • Why do the number of active JMS connections increase?

    <strong>Problem</strong> - Number of active JMS connections and current JMS messages increases until the Weblogic instances crash with an OutOfMemory exception <strong>Setup</strong> - Weblogic v9.2.3, Cluster with 4 Nodes - A JMS Message is sent fro

  • Can we install Best Practice for Fabricated Metals V1.604 on ECC 6.0 EHP5

    Hi Expert Team, We are planning to implement Best Practice for Fabricated Metals V1.604 on ECC 6.0 environment. We are on ECC 6.0 EHP5, but the SAP installation document mentions to install Fabricated Metals V1.604 on ECC 6.0 with EHP4. Also I dont t

  • Stop and go playback in dual layer authoring

    I have a 2 hr movie which came in at just over 7 Gig so I am using Memorex DVD+R DL disk to burn in Best performance mode. The burn went fine but when I watched the movie after the first hour the playback was stop and go. Any ideas ?? New G5 iMac in