Create a setup-frame in Java - java

My problem is the following: I have a Java application, and I would like to create a setup form on it, so i can declare some variables.
How can it be done? And when the setup form is on focus, it should be disabled to perform actions on the main form.
Thanks for any help.
hectai

Create a JDialog and fill it the controls required to display/change options.
One of the JDialog constructors accepts a boolean argument that tells the dialog to be modal, meaning that the user will be unable to focus on the main form.
If you are using AWT, use Dialog instead of JDialog.

You have wide choice :
1- Java Makefile
2- Setup Maker 1.0
3- I recommended : JSmooth

Use swing. When you press "Save" you store the global variables of your app. If you wanna you can show this form at the start of your app.

As jassuncao posted - you're looking for a JDialog to present this to the user. I'd also suggest using the Java Preferences API over setting variables directly. Preferences has support for saving values between runs, using defaults if no value is provided, etc.

Related

Java AWT Robot - how to read item text / label?

I need to select appropriate option from the popup window. Unfortunately, it is not the popup displayed by the web page, so I cannot use Selenium framework for that purpose.
As I checked, it is possible to navigate to different option by pressing arrow keys. Thus keyPress and keyRelease​ from Java AWT Robot should work for me perfectly to select option and confirm the selection by pressing Enter key.
Unfortunately, I do not see a method to read currently selected item text. Without that I cannot find appropriate option. Is it possible to read item label using Java AWT Robot?
If the target application is another java application, then you should be able to get a reference to the component hierarchy and traverse it until you find the text field & label in question.
Assuming it's not a java application, then I don't believe it's possible to do this - at least directly. Robot just provides mouse / keyboard input, but you could use it combined with other classes in the toolkit to at least partially solve your problem.
Use the Robot methods keyPress & keyRelease to input CTRL-A. Then CTRL-C.
Once the text is in the clipboard, you could read it using Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor)
You might be able to use the same approach for a text label, assuming it is selectable.
This question is talking about using java.awt.Robot to alter text in another program (MS excel), but it might provide you some additional ideas for tackling the problem:
How can I select text in another application with java.awt.robot (example: shift+home)

JavaFX: How can I get the character the represents the platform specific SHORTCUT key code?

I am writing a JavaFX application and I have used accelerators to add shortcut keys to the application menus.
Now I am creating the application help and I want to describe the usage of the shortcut keys.
The recommendation for JavaFX accelerators is to use SHORTCUT instead of CONTROL (Windows) and COMMAND (Apple). This works fine and in the menus when running the application on different platforms show the right key combination.
For example, MenuItem Exit I have added the accelerator SHORTCUT_DOWN + X which is displayed as
Ctrl+X under Windows
and
⌘+X under Mac OS
Now I would like to get the explanations (Ctrl+X, ⌘+X) from the system in order to add it to the user help.
Is it possible to ask JavaFX for the presentation of the accelerator in the menu? Or get the presentation of SHORTCUT_DOWN used in the menus?
Thx in advance
Thorsten
According to the documentation, the getDisplayText() method
Returns a string representation of this KeyCombination that is suitable for display in a user interface (for example, beside a menu item).
So all you need is
String acceleratorAsString = menuItem.getAccelerator().getDisplayText();

Saving user settings from GUI

I am currently coding an application, which has an option frame JDialog. This frame contains various checkboxes and text fields that the user can configure.
I want to save the changes the user made to the options.
What is the best way of doing so?
My first thought was implementing it by saving it in a file with the format of e.g.
checkBox1=value;
textArea1="value";
By using the following I could get the field, but I would need to do something like (for the checkbox) myField.isSelected(); which does not work.
Field myField = MyClass.class.getDeclaredField(name);
Thank you in advance.
You can use java.util.prefs.Preferences to store the configuration in your JDialog. This question - Java Preference Manager - discuss about how to create frontend+backend solution by using Preferences (something like JFace org.eclipse.jface.preference)

How disable the spinner in PrinterJob.pringDialog()?

I get the dialog for changing the properties of the print job by invoking the PrinterJob's printDialog() method without any parameter. There is a field where the user can change the the number of copies to be printed on the right-bottom of this dialog.
And now I want to disable this field (the spinner). That is only one copy to be printed and the user can't change it.
Are there any ideas for it
I don't think there is any way (or i am not aware of) to modify the native or the cross-platform Java print dialogs (last one might help you a bit). What you could do is maybe display your own dialog (without a spinner field) and under-the-hood do whatever you want (like PrinterJob.setCopies(1)).
More info i found here.
Also, have a look at the Java tutorial on PrinterJobs.

CNF: Remove SOME popup options (from the ones that are platform contributions)

I need to modify popup menus using CNF. I already read documentation about using action providers and about using "allowsPlatformContribution" to restrict options that are platform contributions. I already used some of these concepts sucessfully to add/remove popup options. But there is one thing I need to do and I don't know how:
Related to PLATFORM CONTRIBUTIONS, I mean declared by org.eclipse.ui.popupMenus (in my case they are standard options: "Validate", "Run As", "Debug As", "Profile As",
"Team", "Compare With", "Restore from Local History...", "Java EE Tools", "Source", "Configure") I just want to show two of them: "Team" and "Compare With" (with all their suboptions).
If using "allowsPlatformContribution=false", then ALL options are removed !. The only idea I have right know is to set this to false and to create an actionProvider for each of both options I need to show, but it seems a bit hard, because I have to add all the suboptions
in it (invoking the appropriate Eclipse action) !. Is that a good way to solve my problem ?. There is another way easier and better ?... I hope so.
Please help. Thanks a lot.
Rosa.
You can use Activities to show/hide elements in the user interface (including menus).
What you have to do is create an Activity and bind it to the UI element. Then, when you enable/disable your activity the platform will automatically show/hide the element bind to it.
For more details on the exact implementation, check out this page:
Eclipse Activities – Hide / Display certain UI elements

Categories

Resources