i haved create this metod for add listeners in my dataChooser.
public final void añadirEsccuhaDataChoser() {
jDateChooser1.getDateEditor().addPropertyChangeListener((PropertyChangeEvent e) -> {
if ("date".equals(e.getPropertyName())) {
listarviajes1();
}
});
this.add(jDateChooser1);
}
but the result who i have obtened after run the project is this.
datachooser moved
but the my original desing is this.
data chooser original position
the method i haved situate into the public vReservas().
situation method
What can I do to prevent the dataChooser from moving?
this is a solution.
solution
The problem is that I created a method, instead of adding the listener in the JdateChooser's internal code.
The code to add the listener is the same, just place it in the custom code option of the jDateChooser.
the ubication of listener
Related
I'm making my custom launch configuration type. I implemented the launch configuration tab and faced the strange problem. When I do the following
private void update() {
setDirty(true);
updateLaunchConfigurationDialog();
}
in one place of my launch configuration tab class, it works fine and Apply button becomes enabled. But when I do it in another place, it doesn't work. I found something similar at https://www.eclipse.org/forums/index.php/t/164755/ , but it didn't help me to solve this problem.
See the code fragments below.
addButton.addMouseListener(new MouseListenerAdapter() {
#Override
public void mouseDown(MouseEvent e) {
moveSelectionToTableViewer(tree.getViewer().getTree().getSelection());
table.refresh();
update(); // Apply button is enabled
}
private void moveSelectionToTableViewer(TreeItem[] selection) {
// ...
}
});
removeButton.addMouseListener(new MouseListenerAdapter() {
#Override
public void mouseDown(MouseEvent e) {
int[] selectionIndices = table.getTable().getSelectionIndices();
table.getTable().remove(selectionIndices);
tree.getViewer().refresh();
update(); // Apply button is NOT enabled!
}
});
How can I solve this?
I don't know your problem from this information alone, But just a few things to check:
Have you verified that setDirty(true) is being called (e.g. with println or breakpoint?)
Have you put a watch on org.eclipse.debug.ui.AbstractLaunchConfigurationTab.fDirty to see if it changes back?
Are you overriding isDirty?
Is removing the an item from the table causing the launch configuration to become invalid in some way, i.e. you can't Apply when invalid values are in the launch config. For example, to be saveable, canSave must return true for all the tabs that are part of the launch configuration.
This is (one of the) place(s) that sets the enabled state of the Apply button:
org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.updateButtons()
/**
* updates the button states
*/
private void updateButtons() {
boolean dirty = isDirty() && canSave();
fApplyButton.setEnabled(dirty);
fRevertButton.setEnabled(dirty);
}
Consider if a mouse listener is what you want. Note that you are responding to MouseDown, that may not do what you expect if a person tabs over to the control and presses Enter/Space instead. The more typical thing to do would be an addSelectionListener for a button. (Could it even be that responding to the event at this unusual time is causing the problem?)
Ik have used this tutorial to define a menu that is built up during runtime. But the next step I want to take is when some event occurs I want to re-build this menu programmatically, for instance by saying to the menu manager, refresh or something like that? Any idea how I can do this?
You can tell the menu manager to remove all items each time the menu is shown, giving you the opportunity to rebuild your menu:
MenuManager mm = new MenuManager();
mm.setRemoveAllWhenShown(true);
mm.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
if(giraffes) {
Action giraffeAction = new Action("Giraffe") {
public void run() {
// do giraffe-y stuff
}
};
mgr.add(giraffeAction);
}
}
});
Control myControl = myViewer.getControl();
myControl().setMenu(mm.createContextMenu(myControl));
Instead of using an ExtensionContributionFactory, use org.eclipse.ui.menus to add a dynamic element to the menu you want. The implementation class you provide subclasses org.eclipse.ui.actions.CompoundContributionItem and you will have the opportunity to rebuild that part of the menu on every menu open.
EDIT: add pointer to example.
See http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org.eclipse.ui.examples.contributions/plugin.xml#n666 for the plugin.xml difference. The implementing class is also contained in that plugin.
I have an application which consists mainly in a JList being displayed on the screen. I would like that everytime I make a change to the AbstractListModel(adding or removing items to the list) , to somehow notify the app that changes have been made and modify the JFrame's title to something like frame_title[unsaved]. After I would save the app, the [unsaved] tag would go away.
I think maybe using the observer/observable technique would do the job but I am not sure how to do it. Maybe there is something much more appropriate to my problem? I am new to java new to java so that is why I came here asking for help. Thanks.
UPDATE : I can't really use the Observer-pattern in my case because I am already extending the AbstractListModel class.
Use this:
AbstractListModel model = ...;
model.addListDataListener(new ListDataListener() {
public void intervalAdded(ListDataEvent e) {
}
public void intervalRemoved(ListDataEvent e) {
}
public void contentsChanged(ListDataEvent e) {
}
});
I have a textbox and one suggestbox. I attach a value change and key up handler to the text box such that whatever the user types (or pastes) into the text box is echo-ed inside the suggestbox. I can get the suggestbox to display the suggestion list by calling showSuggestionList on each value change and key up event.
Now, how do I get the suggestbox to automatically choose the first item in the suggestion list?
One of the methods I tried is to programatically simulate key presses, i.e
suggestBox.setFocus(true);
NativeEvent enterEvent = Document.get().createKeyPressEvent(false, false, false, false, KeyCodes.KEY_ENTER);
DomEvent.fireNativeEvent(enterEvent, suggestBox);
textBox.setFocus(true);
This doesn't work at all. The enter key isn't simulated. Another possible solution is to extend SuggestionBox.SuggestionDisplay, but I'm not too sure how to that. Any pointers appreciated.
Update: I'm still working on this and trying various methods.
Here, I tried to implement my own SuggestionDisplay by subclassing DefaultSuggestionDisplay and overriding getCurrentSelection() to make accessible from my class. This doesn't work either. Null is returned.
private class CustomSuggestionDisplay extends DefaultSuggestionDisplay {
#Override
protected Suggestion getCurrentSelection() {
return super.getCurrentSelection();
}
}
suggestBox.setAutoSelectEnabled(true);
textBox.addKeyUpHandler(new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
suggestBox.setValue(textBox.getText(), true);
suggestBox.showSuggestionList();
if (suggestBox.isSuggestionListShowing()) {
String s = ((CustomSuggestionDisplay) suggestBox.getSuggestionDisplay()).getCurrentSelection().getDisplayString();
Window.alert(s);
}
}
});
Here, I tried to attach a value change handler to the SuggestBox, and casting the event type to SuggestOracle.Suggestion. Again, null is returned.
suggestBox.addValueChangeHandler(new ValueChangeHandler<String>() {
public void onValueChange(ValueChangeEvent<String> event) {
String s = ((SuggestOracle.Suggestion) event).getDisplayString();
Window.alert(s);
}
});
Use suggesBox.setAutoSelectEnabled(true)
Here more info about the SuggestBox of GWT:
You could try using addSelectionHandler in conjunction with setAutoSelectEnabled to receive an event whenever a suggestion is selected. You could also have your Oracle send a message when it suggests something, or your Display send a message when it displays a list:
public class AutomaticallySelectingSuggestionDisplay extends SuggestBox.DefaultSuggestionDisplay {
#Override
protected void showSuggestions(SuggestBox box, Collection<? extends SuggestOracle.Suggestion> suggestions, boolean isDisplayHtml, boolean isAutoSelectEnabled, SuggestBox.SuggestionCallback callback) {
super.showSuggestions(box, suggestions, isDisplayHtml, isAutoSelectEnabled, callback);
fireValueChangeEventWithFirstSuggestion(suggestions);
}
}
This idea feels a little muddled to me, so I hope you can find a solution just using event handlers.
im sitting on this for 4 hours now, and once again I end up on Stackoverflow because I just cant solve this (simple) problem.
I want to fire a method when I click a button, Google gives an Example like this:
// Listen for mouse events on the Add button.
addStockButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
addStock();
}
});
But this creates a new Instance(?..How can they even create an instance of Clickhandler, since its an Interface) everytime the button is clicked. How can I solve this that all buttons share a Clickhandler and the Handler askes the Button which button he is, so he can fire the method attached to that button.
Any Ideas? If you this is to vage information and you require more code please let me know.
Thanks in advance,
Daniel
Java creates a new instance of an anonymous class that implements ClickHandler. Which it can do because you provide an implementation for the onClick function specified by the interface.
This class is however not created when you click on the button but at the moment you call addClickhandler. If you need the handler for multiple events do something like:
ClickHandler handler = new ClickHandler() {
public void onClick(ClickEvent event) {
addStock();
}
};
addStockButton.addClickHandler(handler);
someOtherButton.addClickHandler(handler);
Within the handler you can identify from where the event is coming using event.getSource().
If you have access to your button variables you could simply check the pointer
if (addStockButton == event.getSource()) ...
Or you can cast the result of getSource to the appropriate type and access the properties/methods of the object.
Eelke has already answered your question. I just add that if you would use GWT's UiBinder feature, you could achieve what you want like this:
#UiField
Button addStockButton;
#UiField
Button removeStockButton;
#UiHandler({ "addStockButton", "removeStockButton" })
void handleClickEvents(ClickEvent event)
{
if (event.getSource() == addStockButton)
{
addStock();
}
else if (event.getSource() == removeStockButton)
{
removeStock();
}
}
Its an anonymous instance of the interface, this is like declaring a new class that implements that interface.
I would have to ask why you would want to do this, you would need to make the ClickHandler contain a reference to its parent. You would also need to make the buttons identifiable so you can select the right one in the body of the ClickHandler. Is your need to only have a single instance really that bad that you can't have multiple anonymous instances ?