Re: how to refresh jComboBox in popupMenuWillBecomeVisible



Trufel a écrit :
hello,
i have jComboBox which should calculate its drop-down list size before
opening (it depends on current window size so I decide to put it into
popupMenuWillBecomeVisible method)

void jComboParamNames_popupMenuWillBecomeVisible(PopupMenuEvent e) {
int rowCount = 30; // sample for testing purposes...
myCombo.setMaximumRowCount(rowCount);
// how to refresh combo???
}

Desired size of drop down list will appear... after second click on the
comboBox. Is it possible to refresh it in popupMenuWillBecomeVisible
before showing drop-down list?

thanks
T.

From - Tue

If you intend to recalculate the size depending on the window size, better use ComponentListener on the container of your combo.

public class ComboSizeTest extends JFrame {
private static final String[] data = { "First", "Second", "Third",
"Fourth", "Fifth", "Sixth" };

JComboBox combo = null;

public ComboSizeTest() {
super("Test combo dropdown list resizing");
combo = new JComboBox(data);
this.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
System.out.println("Resized");
combo.setMaximumRowCount(4);
}
});
this.setSize(100, 50);
this.getContentPane().add(combo, BorderLayout.CENTER);
}

public static void main(String[] args) {
new ComboSizeTest().setVisible(true);
}
}

NB: I added a setSize() method after adding the ComponentListener to insure that combo size will be calculated before the frame is made visible.

Rui.
.



Relevant Pages

  • Re: Pointer to my dialog
    ... I gave a modeless dialog solution; ... MyDialog dlg; ... Invoking a modal dialog means that the main application window is disabled. ... void CMyMainWindow::OnCheckNow ...
    (microsoft.public.vc.mfc)
  • Re: Preventing A New Window From Grabbing Focus
    ... If the window can't get focus, ... can't click the cancel button. ... public static void main(Stringargs) { ...
    (comp.lang.java.programmer)
  • How to play video file asynchronously as chunk of buffer ?
    ... I am playing video file synchronously on window mobile m 6.0. ... I want to play video file asynchronously with chunk of buffer. ... afx_msg void OnVideoPlay; ... HRESULT Initialize; ...
    (microsoft.public.win32.programmer.directx.managed)
  • How to play video file asychronously with chunk of buffer?
    ... I am playing video file synchronously on window mobile m 6.0. ... I want to play video file asynchronously with chunk of buffer. ... afx_msg void OnVideoPlay; ... HRESULT Initialize; ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: Mouse Position
    ... VOID* pVertices; ... LONG WINAPI wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM ... HWND CrteWnd(const char *pszName, int x, int y, int w, int h) { ... // Create the application's window ...
    (microsoft.public.win32.programmer.directx.graphics)