views:

92

answers:

1

Hi,

I am trying to implement a search results popup list similar to the style found here:

http://www.inquisitorx.com/

(I'm not trying to implement a Google search, I'm just using this as a rough example of the style I'm working on.)

In any event, I am implementing this by using a JList contained within a JPopupMenu which is popped up underneath a JTextField.

When a user enters search terms, the list changes to reflect different matching results. I then call pack on the JPopupMenu to resize it. This works, however, it creates a slight flicker effect since it is actually hiding the popup and showing a popup. (See the private method getPopup in JPopupMenu where it explicitly does this.)

Is there any way to just get it to just resize itself (aside from using a JWindow)?

A: 

Have you tried setSize()? It looks like that gets handled in JComponent and might avoid the repaint issues.

I think the issue that getPopup is addressing is what to do when the dimensions of the popup will not fit within the window. When that happens, it drops back from a lightweight component to a heavyweight and that definitely requires a hide and show. So, I think if you can guarantee your popup won't extend beyond the window the setSize might do the trick.

Devon_C_Miller
Based on what I read in Sun's code, I beleive you are correct. It uses the PopupFactory to get a popup object which returns light/medium/heavyweight versions depending on the case.There is a setPopupSize method but it also calls the same getPopup method.
Avrom
Using setSize resulted in other undesirable paint issues.
Avrom