Problem with SWT Combobox addSelectionListener() - java

cmbCategory.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
//Do things
}
});
The above code works just fine when I make selection using the control itself, but does not fire when I try changing the index programmatically.
Can anyone help me?

Maybe this could work:
cmbCategory.addModifyListener(new ModifyListener(){
#Override
public void modifyText(ModifyEvent event) {
//Do things
}
});

Related

GWT Tree: selection Listener

I'm trying to add a SelectionListener<TreeItem> on my Tree using the addSelectionHadler() method.
For my proof on onSelection(SelectionEvent<TreeIterm> event) I put a simple Windows.alert() but it don't do anything: when I select a treeItem that color change but doesn't open the window.
I write the Handler but if you want more code tell me.
Thank you.
class SelHand implements SelectionHandler<TreeItem> {
#Override
public void onSelection(SelectionEvent<TreeItem> event) {
Window.alert(event.getSelectedItem().getText());
}
}
SelHand selezionatore = new SelHand();
tree.addSelectionHandler(selezionatore);
Use the straightforward:
tree.addSelectionHandler(new SelectionHandler<TreeItem>() {
#Override
public void onSelection(SelectionEvent<TreeItem> event) {
Window.alert(event.getSelectedItem().getText());
}
});

How can I react to JEditorPane text changes?

I'm working to build an editor. I'd like to know whether the text in JEditorPane is modified or not. How can I react to editor pane text changes?
The following code seems not work.
JEditorPane editorConfig = new JEditorPane();
editorConfig.getDocument().addDocumentListener(new DocumentListener(){
#Override
public void insertUpdate(DocumentEvent e) {
System.out.println("insertUpdate called");
Dialogc.this.refreshTitle();
}
#Override
public void removeUpdate(DocumentEvent e) {
System.out.println("removeUpdate called");
Dialogc.this.refreshTitle();
}
#Override
public void changedUpdate(DocumentEvent e) {
System.out.println("changedUpdate");
Dialogc.this.refreshTitle();
}
});
Thanks very much for your feedback; the code is right for document update. The code did not work because the document of JTextArea are changed in the coming logic.
Thanks
Klaus

How to add MousePressed Eventhandler to addItem new JButton

addItem = new JButton("Add");
gc.gridwidth = GridBagConstraints.RELATIVE;
gc.weightx = 1.0;
panel.add(addItem, gc);
Am I able to make it into something like that:
addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
Instead of this I would want that button, but I have no idea what does that addItem do, since it does not let me to add a name there.
Is there a way how I can do this without modifying the 4 rows of code given at the beginning of the question?
what you can do is to add ActionListener to the button click or if you want you can add MouseListener , actually it depends on what you want to do
addItem.addActionListener(new ActtionListener() {...});
Code using an inner class instead of EventHandler.
addItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//do something
}
});
you can get more information on this in java official website.
Refer: http://docs.oracle.com/javase/7/docs/api/java/beans/EventHandler.html
if you add just the mouse listener you will not get the 'press' event if using keyboard. So, if your requirement is strictly bound to mouse press then use below snippet :)
addItem.addMouseListener(new MouseListener() {
#Override
public void mouseReleased(MouseEvent e) {
// do something
}
#Override
public void mousePressed(MouseEvent e) {
// do something
}
#Override
public void mouseExited(MouseEvent e) {
// do something
}
#Override
public void mouseEntered(MouseEvent e) {
// do something
}
#Override
public void mouseClicked(MouseEvent e) {
// do something
}
});

Get if someone is using a JComboBox?

Like the title says, i need to know if someone is using a combobox.
i.e. when the box is dropped down.
Is there any method to get this? Maybe an actionlistener?
Use JComboBox#addPopupMenuListener():
comboBox.addPopupMenuListener(new PopupMenuListener()
{
#Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e)
{
// ...
}
#Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e)
{
// ...
}
#Override
public void popupMenuCanceled(PopupMenuEvent e)
{
// ...
}
});

JXDatePicker and selectAll()

I want a listener that autoselects the entry on the JXDatePickers editor cell when same gains focus.
DatePicker.getEditor().selectAll();
doesn´t work. So i tried this :
DatePicker.getEditor().addFocusListener(new FocusListener() {
#Override
public void focusGained(FocusEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
DatePicker. getEditor().selectAll();
}
});
}
public void focusLost(FocusEvent e) {
}
});
Any suggestions ?
Edit
just realized that you probably have stand-alone datepicker, and run your snippet: worksforme. So we'll need to dig for differences - what's your swingx/jdk version and OS?
Original
typically, the JFormattedTextField is tricky to convince being selected ;-) See
Combining JXTable with RXTable
and adapt the solution to handle JXDatePicker as well - by adding
if (editor instanceof JXDatePicker) {
LOG.info("got picker: " + editor);
invokeSelectAll(((JXDatePicker) editor).getEditor());
return;
}

Categories