I am using JFace Wizard and I want to set my own text on buttons Next, Back, Finish and Cancel. I found only very old advices which are completely useless today. I also found some solution with external jar files, but I really don't want to add whole library to project only for setting text on 4 buttons...
Is there any reasonable solution?
Thanks in advance
After massive finding and trying, I have to say there is no such way. There are some brutal solutions, but compared with them, adding one jar file to project is much easier and nicer.
I will cite best working solution for me:
You need to download a language pack from here:
http://archive.eclipse.org/eclipse/downloads/drops/L-3.2.1_Language_Packs-200609210945/index.php
NLpack2-eclipse-SDK-3.2.1-gtk.zip works for me while I'm using Eclipse
3.7.2.
Extract org.eclipse.jface.nl2_3.2.1.v200609270227.jar (or other nl for
your language) from the archive and add it to your project. It will be
used automatically.
This do not let you to set texts on buttons, but at least gives you texts translated into your language.
Saw this post. Seems to be the answer to your question.
It basically says to create a dialog using WizardDialog class. Create a class that inherits from Wizard with the implementation of your choice then do below:
WizardDialog wizardDialog = new CustomWizardDialog(shell, new YourWizard());
and then in your CustomWizardDialog do the following:
public class CustomWizardDialog {
#Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
Button finishButton = getButton(IDialogConstants.FINISH_ID);
finishButton.setText("FinishButtonText");
Button cancelButton = getButton(IDialogConstants.CANCEL_ID);
cancelButton.setText("CancelButtonText");
}
}
All that is left is to perform wizardDialog.open() to open dialog.
Related
I am working on an eclipse Plugin, and I would like to use an Editor, set some listeners on the current page(good terminology?), and remove these listeners when the user switches on another page (basically, the user is editing several files, as you could do with the default JAVA editor).
For the moment I have written a class extending StructuredTextEditor. The behavior of the plugin was the one expected, but when I try to work on several files, many problems occur. The main problem, according to me, is that I am not able to get notified when the user opens another page.
I read (and tested) a few things about MultiPageEditor, but it seems like it doesn't integrate an XML editor as default editor. How should I proceed in order to get a MultiPageEditor, with XML syntax coloring, and get notified when the user changes the current page to adjust my listeners ?
Thanks for reading.
the code is not perfect but at least you will have an example of a MultiPageEditor integrating an XMLEditor: https://github.com/fusesource/fuseide/blob/8.0.0.Beta2/editor/plugins/org.fusesource.ide.camel.editor/src/org/fusesource/ide/camel/editor/CamelEditor.java
The idea is to call addPage(new StructuredTextEditor()) inside createPages() method.
regards,
In your editor you can listen to selection changes in the editor text using:
getSelectionProvider().addSelectionChangedListener(listener);
where listener implements ISelectionChangedListener.
This applies to any editor derived from AbstractTextEditor (which includes StructuredTextEditor.
You need to do this fairly late in the editor creation. In the createPartControl method works:
#Override
public void createPartControl(final Composite parent)
{
super.createPartControl(parent);
getSelectionProvider().addSelectionChangedListener(listener);
}
I'd prefer it from Property editor -> Customize Code.
I need to select a folder in one instance and a file in another.
The function will be: On pressing jButton1, jFileChooser1 opens and on confirmation of selection, returns the folder/file path selected to a String strFolderPath/strFilePath.
Thanks in advance for any help.
"I'd prefer it from Property editor -> Customize Code."
No you don't. That's editing the auo-generated code. Yo don't want/need that. The auto-generated code is just for initializing the component and laying them out. It's not meant to be altered (unless you really know what you're doing)
What you want is to add a listener to the button, and write your code for choosing a file in the listener callback. In Netbeans editor you can simply:
Right click on the button from the design view and select Events->Action->actionPerformed
If you go to the source code view, you will see something like
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
}
Inside that method is where out write your code for the file chooser. If you need help with that, I suuggest you take a look at How to use File Choosers. A very simple code example can also be found at the JFileChooser api javadoc
As an aside, these are pretty basic Swing use cases. I would strongly urge you to put down the GUI editor and learn to hand code first. It will make using the editor as tool much easier once you understand the code behind it. If you do want to follow this advice, keep handy the Swing tutorials and slowly go through it at your own pace. There's a lot to take in, but no on can become a ninja overnight, you need to be a grasshopper first :-)
I'm trying to add a ColorPicker to my app. I see a lot a of ColorPickers (the one frome the API'S Samples, the one from Cyanogen, the AmbilWarna library, the HoloColorPicker, and the ColorPickerPreference). I think that the best for my app is the last one, but I don't need to use it on a preference.
So, what I want is to use this library inside my project when I click a button, and then take the resulting code from the SharedPreferences(I think, I don't know it), and use that color as I want for my app.
I try to use only some of the classes (only ColorPickerDialog, ColorPickerView, ColorPickerPanelView and AlphaPatternDrawable) and then I think that I have to do:
ColorPickerDialog dialog = new ColorPickerDialog(Main.this, Color.BLACK);
dialog.show();
And now I don't know how can I have the selected color.
Also I added to my project the xml view.
Any idea?
To know what is the selected color you need to to:
color=dialog.getfinalColor();
So, I think that the problem was easy to solve it. But now the problem is find a listener to detect when the dialog is closed and then to save the variable "color".
I have a gwt suggest box that does an RPC call to get some data from the server and display it. In some cases there are up to 2000 results. Whilst this works fine in chrome when the javascript runs in firefox it freezes the window for 5 seconds and sometime brings up script not responding warnings.
What I wanted to do was something like show 20 results and have a more button that can just append the next 20 without having to call back to the server every time it is clicked. I am fairly new to this, I have tried extending suggestBox and overriding showSuggestions() but it is protected so I can't.
Any suggestions/ ideas would be great.
Cheers,
Rob
See this question for pointers on how to extend the GWT's SuggestBox - basically, you want to provide your own SuggestOracle (it's used for fetching the suggestions), maybe your textbox (see the links in the question I mentioned earlier) and most likely a custom SuggestBox.SuggestionDisplay. Those three are passed via the constructor to SuggestBox. See the existing default implementations (MultiWordSuggestOracle, SuggestBox.DefaultSuggestionDisplay) for some ideas :)
If you want to change source code of SuggestBox see this
you should create com.google.gwt.user.client.ui packeges in your src root and copy there SuggestBox.java. When you use SuggestBox it calls your SuggestBox which is in your src.
Check this also it can be useful too
First solution come to mind is that write your own widget which extends from SuggestBox and the second solution maybe change the default css parameters of suggestbox
.gwt-SuggestBox {
}
.gwt-SuggestBoxPopup {
}
.gwt-SuggestBoxPopup .item {
}
.gwt-SuggestBoxPopup .item-selected {
}
.gwt-SuggestBoxPopup .suggestPopupContent {
}
currently im building an application which is supposed for some sound processing. I'm doing this in java/eclipse with swt/jface.
The processing itself need some options/properties for the algorithem inside. At this time, i have a .properties file which holds all options like:
trimLeadingSilence=20
trimtrailingSilence=20
trimhold=5
fftFrameSize=512
...
I don't want the user to edit these options in a texteditor like notepad++, but within the gui of my app.
Now I think about how to do this. I have 2 "ideas":
Create a class for each option set, and manualy code all these boring gui code lines. Like here for just one option ;-)
Spinner spinnerSilenceBack = new Spinner(shell, SWT.BORDER);
spinnerSilenceBack.setMinimum(0);
spinnerSilenceBack.setMaximum(200);
selection = Integer.valueOf(PropertyManager.getPropertyValue("trimming", "trailingSilence"));
spinnerSilenceBack.setSelection(selection);
spinnerSilenceBack.setIncrement(5);
spinnerSilenceBack.setPageIncrement(20);
spinnerSilenceBack.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int selection = ((Spinner) e.getSource()).getSelection();
int digits = ((Spinner) e.getSource()).getDigits();
int result = (int) (selection / Math.pow(10, digits));
PropertyManager.setPropertyValue("trimming", "trailingSilence", String
.valueOf(result));
}
});
This takes a lot of time due to the fact that there are a lot of different options. So I thought about how I can dynamicly create such gui code, or just dynamicly create these gui windows when starting up the application. At least I would need a config file for the "gui creator" but I don't want to reinvent such a thing-thats why i ask you guys :)
I couldn't get clearly what you are asking.
But, since your question was How to dynamicly build up a gui, i have a a suggestion:
You could use Java Template Engine
library like Freemarker. This
would help you create GUI's that can
be built to work on the fly. With
freemarker you can have one single
template file and then replace the
values accordingly.
I have used it to generate HTML files on the fly. You could evaluate if you can use it otherwise. The API Documentation is rich. So you could go through that once.
Do you mean, you want to make an UI which will have all options you specified? It doesn't matter its a form OR a menu, its up to you. But yeah you can surely configure the names and types in .properties file.
See, you build a Menu OR form in AWT/Swing OR Servlet, but you can read it from properties file right?
You can also configure the same using Spring bean XML definitions, which can provide more support like you can specify all details in some Map OR List etc...
thanks.
I didn't use Swing for a lot of time, so here is just a basic principle.
Config should be done in xml, .properties file is bad here, cuz it doesn't describe objects out-of-the-box.
Add button ("Apply config"), attach actionListener, which 1)parses xml config, 2)then creates form or change settings of existing form, textarea, colors etc.
example for xml config:
found - check it's x_coordinate, y_coord (or use layoutManager, depends on logic), action, than jframe.getLayout().add(new Button(x_coord, y_coord, action).
found - the same.
than jframe.setVisible(true);