JComboBox popupmenu

Hi,
I have a JComboBox with DefaultComboBoxModel. Is there any way i can do this:
When the popup of the JComboBox is down and the user right-clicks on an item in its list, a second popup menu to appear next to the mouse (with options for the item). So far, i 've come up with the following code, extended from class JComboBox, but when the menu appears after the right click, the popup menu of the JComboBox is hidden.
Can someone please help me to fix this? Or does anyone knows a better way to do this or where to look for?
Adding a mouse listener applies only on the text field of the combobox and not its list...
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.applet.*;
import com.borland.jbcl.layout.*;
import javax.swing.border.*;
import javax.swing.plaf.basic.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import javax.swing.event.*;
public class MComboBox extends JComboBox
private JPopupMenu manageItems;
* Inner class for list listener
private class MyComboUI extends MetalComboBoxUI
* List mouse handler
private class MyComboPopup extends BasicComboPopup
MyComboPopup(JComboBox x)
super(x);
private class MyListMouseHandler extends BasicComboPopup.ListMouseHandler
public void mousePressed(MouseEvent e)
if(SwingUtilities.isRightMouseButton(e))
showMenu(e);
else super.mousePressed(e);
public void mouseReleased(MouseEvent e)
if(SwingUtilities.isRightMouseButton(e)==false)
super.mouseReleased(e);
private void showMenu(MouseEvent e)
manageItems.show(e.getComponent(),e.getX(),e.getY());
//override so as to change mouse listener
protected MouseListener createListMouseListener()
return (new MyListMouseHandler());
protected ComboPopup createPopup()
return new MyComboPopup(this.comboBox);
MyComboUI(JPopupMenu x)
super();
manageItems =x;
* Constructors
public MComboBox(JPopupMenu x)
super();
this.setUI(new MyComboUI(x));
public MComboBox(ComboBoxModel t, JPopupMenu x)
super(t);
this.setUI(new MyComboUI(x));
public MComboBox(Vector v,JPopupMenu x)
super(v);
this.setUI(new MyComboUI(x));
public MComboBox(Object [] o,JPopupMenu x)
super(o);
this.setUI(new MyComboUI(x));

Hi,
Adding the following listener:
myCombo.addMouseListener(new MouseAdapter()
public void mouseClicked(MouseEvent e)
System.out.println("Mouse clicked event");
is of no use, since it is never called when i click on the JComboBox (please tell me if it works and i have done a great mistake)
And when i add the listener to the JComboBox editor, it is called only when i click in its text field.
And when i override functions of MetalComboBoxUI,as in the code i posted, i manage to show the JPopupMenu i want, but its own popup hides!
I am really desperate. All i want to do is to show some options (edit, delete, etc) to the items of a JComboBox when the user right-clicks...

Similar Messages

  • Create a PopupMenu when right click onto an item of JComboBox

    How do I make so that, a popupmenu appear only when I right click onto a item of JComboBox. What I have right now is showing a PopupMenu whenever I right click on the frame.
    I got another question to ask if you guys dont mind. How do I set the ComboBox to scroll horizontally. Right now I set the preferredSize of the ComboBox so if the item's names are too long, it will be cut off. Can I set it so that I can scroll horizontally to see the rest of the item's name?

    My English is very poor, so it's hard to explain...
    3.
    // This is just an example code and has not been tested.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.basic.*;
    public class ComboRightClickTest{
      public JComponent makeUI(final JFrame frame) {
        frame.setGlassPane(new LockingGlassPane());
        String[] items = {"test1", "test2", "test3"};
        JComboBox combo = new JComboBox(items);
        combo.setUI(new BasicComboBoxUI() {
          protected ComboPopup createPopup() {
            return new BasicComboPopup( comboBox ) {
              protected JList createList() {
                return new JList( comboBox.getModel() ) {
                  public void processMouseEvent(MouseEvent e)  {
                    if(e.isPopupTrigger()) {
                      String s = getSelectedValue().toString();
                      frame.getGlassPane().setVisible(true);
                      final JPopupMenu m = new JPopupMenu();
                      final JMenuItem i = new JMenuItem(
                          new AbstractAction("del:"+s) {
                        public void actionPerformed(ActionEvent ae) {
                          comboBox.removeItemAt(getSelectedIndex());
                          frame.getGlassPane().setVisible(false);
                          m.setVisible(false);
                      i.addMouseListener(new MouseAdapter() {
                        public void mouseEntered(MouseEvent me) {
                          i.setBackground(getSelectionBackground());
                        public void mouseExited(MouseEvent me) {
                          i.setBackground(getBackground());
                      m.add(i);
                      Point p = e.getPoint();
                      SwingUtilities.convertPointToScreen(p, this);
                      m.show(null, p.x, p.y);
                      return;
                    super.processMouseEvent(e);
        JPanel p = new JPanel(new BorderLayout());
        p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        p.add(combo, BorderLayout.NORTH);
        p.setPreferredSize(new Dimension(320, 100));
        return p;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          public void run() { createAndShowGUI(); }
      public static void createAndShowGUI() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.getContentPane().add(new ComboRightClickTest().makeUI(f));
        f.setResizable(false); //XXX
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    class LockingGlassPane extends JComponent {
      public LockingGlassPane() {
        setOpaque(false);
      @Override public void setVisible(boolean isVisible) {
        boolean oldVisible = isVisible();
        super.setVisible(isVisible);
        JRootPane rootPane = SwingUtilities.getRootPane(this);
        if(rootPane!=null && isVisible()!=oldVisible) {
          rootPane.getLayeredPane().setVisible(!isVisible);
      @Override public void paintComponent(Graphics g) {
        JRootPane rootPane = SwingUtilities.getRootPane(this);
        if(rootPane!=null) {
          http://weblogs.java.net/blog/alexfromsun/archive/2008/01/
          rootPane.getLayeredPane().print(g);
        super.paintComponent(g);
    }

  • Popupmenu & JComboBox shows up behind JInternalFrame on glasspane

    Till Java 6 update 12 we used setLightWeightPopupEnabled on the popupmenus and JComboBoxes to make them appear on the toplevel when showing the glasspane. The situation is as followed:
    - A Swing application
    - Over the Swing application is a glasspane (extends JPanel)
    - Added on the glasspane is a JInternalFrame (with on it components like a JPanel)
    - When clicking with right mouse button, a popupmenu shows up. When using setLightWeightPopupEnabled it works perfectly
    But when Java 6 update 12 was released, the popupmenu and JComboBox popup are shown behind the JInternalFrame (but above the glasspane).
    SUN made some adjustments in the system. Does anyone knows how I can solve the problem as described above?

    I made a simple code example which simulates the problem. The combobox popup falls behind the JInternalFrame. Another strange effect is when you try to resize the JInternalFrame, the JInternalFrame is closed.
    import java.awt.BorderLayout;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JPanel;
    public class PopupBehindInternalFrame
         public static void main (String args[]){
              JFrame frame = new JFrame();
              JPanel panel = new JPanel();
              frame.getContentPane().add(panel);
              frame.setSize(800, 600);
              frame.setVisible(true);
              JInternalFrame jif = new JInternalFrame();
              jif.setSize(400, 300);
              jif.setResizable(true);
              JPanel panelJif = new JPanel();
              jif.add(panelJif, BorderLayout.SOUTH);
              JComboBox cb = new JComboBox();
              cb.setSize(100, 10);
              cb.addItem("Test 1");
              cb.addItem("Test 2");
              cb.addItem("Test 3");
              cb.addItem("Test 4");
              cb.setLightWeightPopupEnabled(false);
              panelJif.add(cb);
              panel.getRootPane().setGlassPane(GlassPane.getInstance());
              GlassPane.getInstance().setVisible(true);
              GlassPane.getInstance().add(jif);
              jif.setVisible(true);
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.event.MouseAdapter;
    import javax.swing.InputVerifier;
    import javax.swing.JComponent;
    import javax.swing.JPanel;
    public class GlassPane extends JPanel
         private static final long serialVersionUID = 1L;
         private static GlassPane glassPane = null;
         private Color color = new Color(0, 128, 128, 128);
         public GlassPane()
              setOpaque(false);
              setLayout(null);
              addMouseListener(new MouseAdapter()
              setInputVerifier(new InputVerifier()
                   public boolean verify(JComponent input)
                        return !isVisible();
         protected void paintComponent(Graphics g)
              if (getComponents().length > 0)
                   Graphics2D g2 = (Graphics2D) g.create();
                   g2.setColor(color);
                   g2.fillRect(0, 0, getWidth(), getHeight());
                   g2.dispose();
              else
                   super.paintComponent(g);
         public static GlassPane getInstance()
              if (glassPane == null)
                   glassPane = new GlassPane();
              return glassPane;
    }

  • JCombobox in popupmenu

    Hello everyone.
    I've got a JPanel with some textfields and a combobox. This panel is placed inside a popupmenu. The problem is when I press the combobox, the popupmenu disappears. Only the dropdown list of the combobox remains.
    I would like the rest of the components to stay visible when i press the combobox.
    Any suggestions?

    Create a [url http://www.physci.org/codes/sscce.jsp]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

  • JpopupMenu with a JComboBox problem

    Hi,
    Well I need to make a popupMenu which contains a JComboBox, when I invoke the method show(, ,) of the popupMenu, everything looks fine.
    But when I press on the comboBox to view its data, I can only see the drop list and the popupMenu disappears.
    The problem occurs after that, when I try to choose a selection from the comboBox list, it also disappears without invoking the listener.
    I believe it might be a focusing problem.
    If anyone has a solution, I'd appreciate it??
    Thanks & Regards,
    ES_Coders

    An other solution is to work use a BasicComboPopup
    - import javax.swing.plaf.basic.BasicComboPopup -
    It works quiet well
    You can use a normal JComboBox for storing the entrys.
    See the documentation of the class.
    You should only watch for the add or remove methods. Those methods must be invoked on the JComboBox not on the BasicComboPopup.
    Olek

  • JComboBox doesn't show data...help please

    I have created a JComboBox. I place an array of strings in that jcombobox. I'm sure the data is there, however, it is not shown.
    I traced the problem back to light/heavy weight problems.
    When i use a lightweight JComboBox it doesn't drop down at all.
    This is probably because there's a JLabel under it.
    However, when i mean it an heavyweight object
    (by calling PopupMenu.setLightWeightPopupEnabled(false) )
    the dropdown shows up but it is empty.
    Has anyone had the same problem or something similar?
    help would be appreciated...
    thanx.

    Well here's a code snippet:
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    Calendar cal = Calendar.getInstance();
    Integer[] years = new Integer[21];
    Integer[] months = new Integer[13];
    Integer[] days = new Integer[32];
    for(int i = 0; i < 20; i++)
    years[i] = new Integer(cal.get(Calendar.YEAR) + i);
    startDateYear = new JComboBox(years);
    startDateYear.setMaximumRowCount(3);
    Now here you see how i fillup the JComboBoxes, i've already verified that there actually are objects in the JComboBox so that's not the problem.
    the first line of code is to make the JComboBoxes make a popupmenu that's heavyweight.
    so it should be in front of other lightweighted components (namely a JLabel underneath the JComboBox ) .
    Now i see it drop down, however it shows absolutely no data. It doesn't even show a scrollbar, you can just see gray space outline of where the dropdown menu of the JComboBox should be.
    does this help?

  • JComboBox customization

    Hi folks,
    I try to use GlassPane to dispatch event to a JComboBox in a JTable. The problem occurs when I try to dispatch events to the popup menu. First, when the mouse moves into the region of popup, SwingUtilities.getDeepestComponenet() always return BasicComboPopup$2 instead of the BasicComboPopup object I returned in my own createPopup method (I override the BasicComboPopup class). Second, if there gets too many items in popup to fit in 1 page, vectical scroll bar appears. At this time, I scroll to the 2nd page of popup, click the mouse on any item and when I try to dispatch this click event to BasicComboPopup$2, strange that always the item in first page is selected. Any hints ?
    Also, is there any detailed explanation of JComboBox implementation avilable on the net ? e.g. how BasicComboPopup, ArrorButton related to JCombobox, how scrolling is handled, etc. I think this helps me to locate what is going wrong in my program.

    To customise a full JComboBox might take some UI work.
    I'd suggest going with a custom JTextField and popupmenu if you want that look.
    Tip: use custom painting to get the arrow painted on the textfield
    ICE

  • Cancel the dropdown menu hiding in JComboBox

    Hi!
    I'm using the JComboBox as the celleditor for a JTable. My problem is that the combo hides it's menu everytime I press a key. Does anybody know how I can stop it from hiding it's meny after I type a key? (to make it hide it's drop-down menu at will)
    I would appreciate much any help

    Actually you gave me a good idea of making it editable. This way I archieve two aims:
    1. The user has an area where to type, and he can see what he types.
    2. The user (prolly) knows that when typing is done he should press "Enter" to get rid of the popupmenu below the textfield.. and here I'm catching the "Enter" key and look fast through the combo's vector list to find the matching string and by finding it I make it selected in the combobox.. BUT my problem is that I CAN'T find a way to add a keylistener to the textfield where the user is typing it's string. By saying textfield I mean the area/component where the user types something (meanwhile the dropdownmenu is below). I tried to tie a keylistener to the renderer of the Combobox:
    ( (JLabel)getRenderer() ).addKeyListener( this );but it's not a the textfield where the user is typing.. I just can't find this textfield to tie my listener to it! please help finding a way!
    and thanks again ICE I'm one step closer!

  • Dynamic PHTMLB PopupMenu

    Anyone have any idea why I can't get my popupmenu to work?  I have two sets of data, one we'll call code groups and the other group items.  I simply want the group items to be a submenu of their group.  I can get exactly one group item to slide out, and it looks strange in a large font.
    Anyone see something I don't? 
    method ZFILL_OTEIL_POPUP .
    data: wa_popup like line of oteilgroup,
          lv_group type zqpgt_tab,
          lv_item  type zqpct_tab,
          lv_text type string,
          separator(3) value ' - '.
    field-symbols: <group> type zqpgt,
                   <item>  type zqpct.
    lv_group = me->zget_group_codes( p_katalogart = 'B' ).
    lv_item = me->zget_item_codes( p_katalogart = 'B' ).
    data: id type string,
          index type string.
    loop at lv_group assigning <group>.
      clear wa_popup.
      clear id.
        refresh oteilitem.
      move sy-tabix to index.
      concatenate 'oteilSubPopup' index into id.
      concatenate <group>-codegruppe <group>-kurztext into lv_text
                  separated by separator.
      wa_popup-menuitemid = 'oteilPopup'.
      wa_popup-submenuid  = id.
      wa_popup-text = lv_text.
    wa_popup-cancheck = 'X'.
      wa_popup-enabled  = 'X'.
      append wa_popup to oteilgroup.
      loop at lv_item assigning <item>
           where codegruppe = <group>-codegruppe.
        clear wa_popup.
        concatenate <item>-code <item>-kurztext into lv_text
                    separated by separator.
        wa_popup-menuitemid = id.
        wa_popup-text = lv_text.
       wa_popup-cancheck = 'X'.
        wa_popup-enabled  = 'X'.
        append wa_popup to oteilitem.
      endloop.
        append oteilitem to oteilitems. "deeply structured itab
    endloop.
    endmethod.
    LAYOUT
                    <td><htmlb:label for="object" text="Object Code"/></td>
                    <td><htmlb:inputField id="damage" value="//model/notif_fields.fecod" disabled="true"/>
                        <phtmlb:popupTrigger id="oteilTrigger"
                                             popupMenuId="oteilPopup"
                                             isInteractive="true" >
                        <htmlb:image src="s_b_hint.gif" />
                        </phtmlb:popupTrigger>
                        <phtmlb:popupMenu id="oteilPopup"
                                          firstVisibleItemIndex="1"
                                          maxVisibleItems="25"
                                          items="<%=oteilgroup%>">
                        </phtmlb:popupMenu>
    <% data: wa_item type PHTMLB_POPUPMENUITEMS,
             id type string,
             index type string. %>
    <% loop at oteilitems into wa_item.
           move sy-tabix to index.
           concatenate 'oteilSubPopup' index into id. %>
           <phtmlb:popupMenu id="<%= id %>"
                             onSelect="myOteil"
                             firstVisibleItemIndex="1"
                             maxVisibleItems="25"
                             items="<%= wa_item %>">
           </phtmlb:popupMenu>
           <% refresh wa_item. %>
    <% endloop. %>

    Hi Thomas,
             Thanks for the reply.
             As you have said there are no background or MouseOver color for popupMenu. I am using a workaround for this by putting the popMenuItems in an html table and then changing the above said attributes for the individual cells. This works fine in normal menu but no effect when used with popupMenu. If you want I can send you the code but that will be possible tomorrow.
    Regards
    PRAFUL

  • Not Updating the Values in the JComboBox and JTable

    Hi Friends
    In my program i hava Two JComboBox and One JTable. I Update the ComboBox with different field on A Table. and then Display a list of record in the JTable.
    It is Displaying the Values in the Begining But when i try to Select the Next Item in the ComboBox it is not Updating the Records Eeither to JComboBox or JTable.
    MY CODE is this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.DefaultComboBoxModel.*;
    import javax.swing.table.*;
    import java.sql.*;
    import java.util.*;
    public class SearchBook extends JDialog implements ActionListener
         private JComboBox comboCategory,comboAuthor;
         private JSplitPane splitpane;
         private JTable table;
         private JToolBar toolBar;
         private JButton btnclose, btncancel;
         private JPanel panel1,panel2,panel3,panel4;
         private JLabel lblCategory,lblAuthor;
         private Container c;
         //DefaultTableModel model;
         Statement st;
         ResultSet rs;
         Vector v = new Vector();
         public SearchBook (Connection con)
              // Property for JDialog
              setTitle("Search Books");
              setLocation(40,110);
              setModal(true);
              setSize(750,450);
              // Creating ToolBar Button
              btnclose = new JButton(new ImageIcon("Images/export.gif"));
              btnclose.addActionListener(this);
              // Creating Tool Bar
              toolBar = new JToolBar();
              toolBar.add(btnclose);
              try
                   st=con.createStatement();
                   rs =st.executeQuery("SELECT BCat from Books Group By Books.BCat");
                   while(rs.next())
                        v.add(rs.getString(1));
              catch(SQLException ex)
                   System.out.println("Error");
              panel1= new JPanel();
              panel1.setLayout(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.HORIZONTAL;
              lblCategory = new JLabel("Category:");
              lblCategory.setHorizontalAlignment (JTextField.CENTER);
              c.gridx=2;
              c.gridy=2;
              panel1.add(lblCategory,c);
              comboCategory = new JComboBox(v);
              comboCategory.addActionListener(this);
              c.ipadx=20;
              c.gridx=3;
              c.gridwidth=1;
              c.gridy=2;
              panel1.add(comboCategory,c);
              lblAuthor = new JLabel("Author/Publisher:");
              c.gridwidth=2;
              c.gridx=1;
              c.gridy=4;
              panel1.add(lblAuthor,c);
              lblAuthor.setHorizontalAlignment (JTextField.LEFT);
              comboAuthor = new JComboBox();
              comboAuthor.addActionListener(this);
              c.insets= new Insets(20,0,0,0);
              c.ipadx=20;
              c.gridx=3;
              c.gridy=4;
              panel1.add(comboAuthor,c);
              comboAuthor.setBounds (125, 165, 175, 25);
              table = new JTable();
              JScrollPane scrollpane = new JScrollPane(table);
              //panel2 = new JPanel();
              //panel2.add(scrollpane);
              splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panel1,scrollpane);
              splitpane.setDividerSize(15);
              splitpane.setDividerLocation(190);
              getContentPane().add(toolBar,BorderLayout.NORTH);
              getContentPane().add(splitpane);
         public void actionPerformed(ActionEvent ae)
              Object obj= ae.getSource();
              if(obj==comboCategory)
                   String selecteditem = (String)comboCategory.getSelectedItem();
                   displayAuthor(selecteditem);
                   System.out.println("Selected Item"+selecteditem);
              else if(obj==btnclose)
                   setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
              else if(obj==comboAuthor)
                   String selecteditem1 = (String)comboAuthor.getSelectedItem();
                   displayavailablity(selecteditem1);
                   //System.out.println("Selected Item"+selecteditem1);
                   System.out.println("Selected Author"+selecteditem1);
         private void displayAuthor(String selecteditem)
              try
              {     Vector data = new Vector();
                   rs= st.executeQuery("SELECT BAuthorandPublisher FROM Books where BCat='" + selecteditem + "' Group By Books.BAuthorandPublisher");
                   System.out.println("Executing");
                   while(rs.next())
                        data.add(rs.getString(1));
                   //((DefaultComboBoxModel)comboAuthor.getModel()).setVectorData(data);
                   comboAuthor.setModel(new DefaultComboBoxModel(data));
              catch(SQLException ex)
                   System.out.println("ERROR");
         private void displayavailablity(String selecteditem1)
                   try
                        Vector columnNames = new Vector();
                        Vector data1 = new Vector();
                        rs= st.executeQuery("SELECT * FROM Books where BAuthorandPublisher='" + selecteditem1 +"'");     
                        ResultSetMetaData md= rs.getMetaData();
                        int columns =md.getColumnCount();
                        String booktblheading[]={"Book ID","Book NAME","BOOK AUTHOR/PUBLISHER","REFRENCE","CATEGORY"};
                        for(int i=1; i<= booktblheading.length;i++)
                             columnNames.addElement(booktblheading[i-1]);
                        while(rs.next())
                             Vector row = new Vector(columns);
                             for(int i=1;i<=columns;i++)
                                  row.addElement(rs.getObject(i));
                             data1.addElement(row);
                             //System.out.println("data is:"+data);
                        ((DefaultTableModel)table.getModel()).setDataVector(data1,columnNames);
                        //DefaultTableModel model = new DefaultTableModel(data1,columnNames);
                        //table.setModel(model);
                        rs.close();
                        st.close();
                   catch(SQLException ex)
    }Please check my code and give me some Better Solution
    Thank you

    You already have a posting on this topic:
    http://forum.java.sun.com/thread.jspa?threadID=5143235

  • JComboBox causing GTK-WARNING and GTK-CRITICAL on Ubuntu 8.04

    I was wondering why whenever I use the GTK Look and Feel, my JComboBox's cause GTK issues. They also don't display right...
    Here is the code I am using....
    import javax.swing.*;
    public class ComboBoxDisplayTest extends JFrame
      public ComboBoxDisplayTest()
        try
          UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
          SwingUtilities.updateComponentTreeUI(this);
        catch(Exception ex)
          ex.printStackTrace();
        JComboBox cb = new JComboBox();
        this.add(cb);
        cb.addItem("Item 1");
        cb.addItem("Item 2");
      public static void main(String[] args)
        ComboBoxDisplayTest c = new ComboBoxDisplayTest();
        c.pack();
        c.setVisible(true);
    }This is what get's printed onto the terminal when I run the program:
    java ComboBoxDisplayTest
    (<unknown>:7078): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a GtkComboBoxEntry (need an instance of GtkEntry or of a subclass)
    (<unknown>:7078): Gtk-CRITICAL **: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failedWhat exactly is going on?
    Is there something wrong with my code?
    Is there any way to fix this?
    Any answers are much appreciated...
    Thanks

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6624717
    as far as i know (i am using Ubuntu 7.10 & OpenJDK 1.6.0_0-b11 & Sun JDK) not fixed yet ....
    Ronald

  • Associate Action with jcombobox item

    Is it possible to associate a particular Action with a jcombobox item (for example using setAction()). When the user selects a particular item of jcombobox, the Action must be triggered.
    regards,
    Nirvan.

    Hi,
    You can associate a particular action with a JComboBox. As per my understanding u can add one action perfrom action to combobox or itemStateChanged action
    if u add action perform action, u need to add the following method to ur logic.
    JComboBox combobox=new JComboBox();
        combobox.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
             JComboBox combo = (JComboBox)evt.getSource();
                if(combo.getSelectedItem().equals("LOCATION")) {
                A a = new A();
                a.show();
            } else if(combo.getSelectedItem().equals("HOUSE")) {
                B b= new B();
                b.show();
            });if action is ItemStateChanged then add the following method.
    combobox.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    and write your logic here which one needs to be triggered when this action performed.
            });Hope this will help to you....
    Thanks & Regards,
    Maadhav..

  • Retrieving values from a JComboBox - Design question.

    I would like some design guidance on a problem that I am hoping has been solved before. Here is my situation:
    I have a JComboBox that I populate with String values from a database table. The exact set of values to be loaded into the JComboBox varies according values specified elsewhere on the GUI.
    When I select an item from the JComboBox, I need to read the database to retrieve more information. The text is not sufficient for me to identify the data I need, so I need to get the table key from somewhere.
    Is there anyway I can associate my table key with the text value inside the JComboBox and retrieve it when the user selects a drop down value from the JComboBox?
    Many thanks in advance.

    when you load the data from the db, try to get ALL the information needed: item label+item value+description. put this data into a map (a hashmap) for example using a unique identifier. For example, use a numeric index. In this case, the item value should be the index that uniquely identifies your items.
    create a simple bean that encapsulates the item contents: index+value+label, description.
    Doing this will avoid the huge db access occurences.
    hth

  • How to change font/ font color etc in a graphic object using JCombobox?

    Hello
    My program im writing recently is a small tiny application which can change fonts, font sizes, font colors and background color of the graphics object containing some strings. Im planning to use Jcomboboxes for all those 4 ideas in implementing those functions. Somehow it doesnt work! Any help would be grateful.
    So currently what ive done so far is that: Im using two classes to implement the whole program. One class is the main class which contains the GUI with its components (Jcomboboxes etc..) and the other class is a class extending JPanel which does all the drawing. Therefore it contains a graphics object in that class which draws the string. However what i want it to do is using jcombobox which should contain alit of all fonts available/ font sizes/ colors etc. When i scroll through the lists and click the one item i want - the graphics object properties (font sizes/ color etc) should change as a result.
    What ive gt so far is implemented the jcomboboxes in place. Problem is i cant get the font to change once selecting an item form it.
    Another problem is that to set the color of font - i need to use it with a graphics object in the paintcomponent method. In this case i dnt want to create several diff paint.. method with different property settings (font/ size/ color)
    Below is my code; perhaps you'll understand more looking at code.
    public class main...
    Color[] Colors = {Color.BLUE, Color.RED, Color.GREEN};
            ColorList = new JComboBox(Colors);
    ColorList.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ev) {
                     JComboBox cb = (JComboBox)ev.getSource();
                    Color colorType = (Color)cb.getSelectedItem();
                    drawingBoard.setBackground(colorType);
              });;1) providing the GUI is correctly implemented with components
    2) Combobox stores the colors in an array
    3) ActionListener should do following job: (but cant get it right - that is where my problem is)
    - once selected the item (color/ font size etc... as i would have similar methods for each) i want, it should pass the item into the drawingboard class (JPanel) and then this class should do the job.
    public class DrawingBoard extends JPanel {
           private String message;
           public DrawingBoard() {
                  setBackground(Color.white);
                  Font font = new Font("Serif", Font.PLAIN, fontSize);
                  setFont(font);
                  message = "";
           public void setMessage(String m) {
                message = m;
                repaint();
           public void paintComponent(Graphics g) {
                  super.paintComponent(g);
                  //setBackground(Color.RED);
                  Graphics2D g2 = (Graphics2D) g;
                  g2.setRenderingHint             
                  g2.drawString(message, 50, 50);
           public void settingFont(String font) {
                //not sure how to implement this?                          //Jcombobox should pass an item to this
                                   //it should match against all known fonts in system then set that font to the graphics
          private void settingFontSize(Graphics g, int f) {
                         //same probelm with above..              
          public void setBackgroundColor(Color c) {
               setBackground(c);
               repaint(); // still not sure if this done corretly.
          public void setFontColor(Color c) {
                    //not sure how to do this part aswell.
                   //i know a method " g.setColor(c)" exist but i need to use a graphics object - and to do that i need to pass it in (then it will cause some confusion in the main class (previous code)
           My problems have been highlighted in the comments of code above.
    Any help will be much appreciated thanks!!!

    It is the completely correct code
    I hope that's what you need
    Just put DrawingBoard into JFrame and run
    Good luck!
    public class DrawingBoard extends JPanel implements ActionListener{
         private String message = "message";
         private Font font = new Font("Serif", Font.PLAIN, 10);
         private Color color = Color.RED;
         private Color bg = Color.WHITE;
         private int size = 10;
         public DrawingBoard(){
              JComboBox cbFont = new JComboBox(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
              cbFont.setActionCommand("font");
              JComboBox cbSize = new JComboBox(new Integer[]{new Integer(14), new Integer(13)});
              cbSize.setActionCommand("size");
              JComboBox cbColor = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbColor.setActionCommand("color");
              JComboBox cbBG = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbBG.setActionCommand("bg");
              add(cbFont);
              cbFont.addActionListener(this);
              add(cbSize);
              cbSize.addActionListener(this);
              add(cbColor);
              cbColor.addActionListener(this);
              add(cbBG);
              cbBG.addActionListener(this);
         public void setMessage(String m){
              message = m;
              repaint();
         protected void paintComponent(Graphics g){
              super.paintComponent(g);
              Graphics2D g2 = (Graphics2D)g;
              g2.setColor(bg);//set background color
              g2.fillRect(0,0, getWidth(), getHeight());          
              g2.setColor(color);//set text color
              FontRenderContext frc = g2.getFontRenderContext();
              TextLayout tl = new TextLayout(message,font,frc);//set font and message
              AffineTransform at = new AffineTransform();
              at.setToTranslation(getWidth()/2-tl.getBounds().getWidth()/2,
                        getWidth()/2 + tl.getBounds().getHeight()/2);//set text at center of panel
              g2.fill(tl.getOutline(at));
         public void actionPerformed(ActionEvent e){
              JComboBox cb = (JComboBox)e.getSource();
              if (e.getActionCommand().equals("font")){
                   font = new Font(cb.getSelectedItem().toString(), Font.PLAIN, size);
              }else if (e.getActionCommand().equals("size")){
                   size = ((Integer)cb.getSelectedItem()).intValue();
              }else if (e.getActionCommand().equals("color")){
                   color = (Color)cb.getSelectedItem();
              }else if (e.getActionCommand().equals("bg")){
                   bg = (Color)cb.getSelectedItem();
              repaint();
    }

  • Problem with JComboBox in a JPanel

    I have a JComboBox in a JPanel (with a gridbaglayout), and I add items to the combobox:
    String[] stateList={"AL",.....};
    JCombobox stateCB=new JComboBox(stateList);
    and when I run the application, the states appear in the box, but when I click on the box, there is no drop-down list!
    any ideas?

    Is the combobox Enabled if it is then after adding it to anything set it to true cause i poersonally tried out as u have given it it works and else if it does not show a list then use the setmodel function and set the model to DefaultComboBoxModel and then add the items using a for loop

Maybe you are looking for

  • Flash Chart : Percentage values in the pie chart and  values in the legend

    Hi All, Query is : SELECT null link ,GN.region Region ,ROUND(100*ratio_to_report(COUNT(DISTINCT GN.submittedbyemail)) over (),2) value FROM goodnews_stories GN GROUP BY GN.region I use the above query to display the flash pie chart percentage values.

  • Size of digital images for reproduction in iPhoto Books

    I have been reading comments in this forum and have become confused reading about image size in iphoto books. I have some very old scanned photos saved in tiff format files on an external hard-drive and want to make a book using them. I don't want to

  • LEAD MANAGEMENT- how to make fields mandatory

    Is there a provision in lead management to make the fields mandatory so that lead number is not generated without filling the mandatory fields/ as it is in business partnerm using field groupings in customizing (eg. without submitting address proof B

  • Can you change the format when converting pdf to excel?

    example.  I'm trying to export a PDF file to excel.  However, the PDF file isn't in a table/spreadsheet format so when it exports to excel, I can't sort at all.  It doesn't convert into any sortable columns.  Is there a way to change the format on th

  • Lenovo K410 splash screen

    I am trying to add a pci-e raid card to have a mirrored hard drive set up.  To set up the card, you need to press F4 at the appropriate time during the boot process.  Unfortunately, all you see is the LENOVO bios splash screen.  Four tech calls and 3