open combobox' dropdown programmatically? [message #462702] |
Mon, 17 October 2005 09:57  |
Eclipse User |
|
|
|
i would like to drop down a combobox on "focus in", so the content is
presented to the user already, with no need to click the arrow-button.
another solution would be to transfer the "focus in" of the text-part to
the arrow-button immediately.
it's decisive the comboi drops down with just one key or mouse action
(while pressing TAB or clicking the mouse into the left part of the combo).
how to do that?
|
|
|
|
|
|
Re: open combobox' dropdown programmatically? [message #462903 is a reply to message #462702] |
Thu, 20 October 2005 13:57   |
Eclipse User |
|
|
|
Hi Arne,
if Win32-only is an option for you, you might try out this little snippet.
Regards,
Boris
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class CComboDemo {
/**
* Open a Combo programatically (Win32 only)
*
* @param combo
* Combo
* @param show
* (boolean) popped up or not?
*/
private static void showPopup(Combo combo, boolean show) {
if (!combo.isDisposed()) {
OS.SendMessage(combo.handle, OS.CB_SHOWDROPDOWN, show ? 1 : 0, 0);
}
}
/**
* Has the Combo already popped up? (Win32 only)
*
* @param combo
* Combo
* @return (boolean) popped up or not?
*/
private static boolean isPopupShowing(Combo combo) {
boolean result = false;
if (!combo.isDisposed()) {
result = (OS.SendMessage(combo.handle, OS.CB_GETDROPPEDSTATE, 0, 0) !=
0);
}
return result;
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Demonstrates drop down on focus in");
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
shell.setLayout(gridLayout);
Text text = new Text(shell, SWT.BORDER);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
text.setLayoutData(gridData);
final Combo combo = new Combo(shell, SWT.READ_ONLY);
for(int i = 0; i < 10; i++){
combo.add("ComboItem " + i);
};
combo.select(0);
combo.setLayoutData(gridData);
combo.addListener(SWT.FocusIn, new Listener(){
public void handleEvent(Event e){
showPopup(combo, !isPopupShowing(combo));
}
});
Button button = new Button(shell, SWT.PUSH);
button.setText("Push Me");
button.setLayoutData(gridData);
shell.setSize(330, 100);
Monitor primary = Display.getDefault().getPrimaryMonitor();
Rectangle bounds = primary.getBounds();
Rectangle rect = shell.getBounds();
Point pt = new Point(bounds.x + (bounds.width - rect.width) / 2,
bounds.y + (bounds.height - rect.height) / 2);
shell.setLocation(pt);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04860 seconds