I'm using the Eclipse AWT framework, and I've got a combobox.
I've set the visible amount of items in the combobox to 0, so that clicking the dropdown doesn't show anything (even though the box is populated).
I have an AutoCompleteField on the box, so that anyone typing into the combobox sees the Eclipse-style AutoCompleteField. This works perfectly.
However, I'd like to be able to trigger the AutoCompleteField to appear in certain circumstances, and not just when the user starts typing. For instance, I'd like it to appear when the user clicks the dropdown triangle, so it's like the Eclipse-style AutoCompleteField appears instead of the normal drop-down.
Unfortunately, the AutoCompleteField exposes NO useful methods, and I hardly understand how it works.
How can I get it to appear at whim?
I assume you mean the SWT / JFace AutoCompleteField (AWT is the old Java GUI).
AutoCompleteField is only intended for the simplest use of the auto complete, for anything more complex you need to use the lower level classes.
This is what AutoCompleteField sets up:
Control control = your control
IControlContentAdapter controlContentAdapter = your control context adapter
String[] proposals = your proposals
SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(proposals);
proposalProvider.setFiltering(true);
ContentProposalAdapter adapter = new ContentProposalAdapter(control, controlContentAdapter, proposalProvider, null, null);
adapter.setPropagateKeys(true);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
It is the ContentProposalAdapter that can open the assist as required using the openProposalPopup() method - this is a protected method so would need to use a class derived from ContentProposalAdapter to use it.
ContentProposalAdapter also has parameters for a KeyStroke to activate the assist and a set of auto-activation characters.
Related
I'm currently learning how to create a program with Java and jFrame. One problem I have is that I cant create new "forms" (how they are called in visualbasic) or windows. I'm using "Java-Editor", a usually very simple editor for things like that. Can anyone help me create a new form?
Thanks for your help in advance,
Till
From JFrame I assume that you are using Swing, and that you want multiple windows for your application. Your app should only use one JFrame object, if you need more windows (usually these are popup messages) then you can use dialogs. The class for this is JOptionPane.
Here is an example:
JOptionPane.showMessageDialog(null,"title","content",JOptionPane.INFORMATION_DIALOG);
As you can see you can control the title and the content displayed. Note that for the content parameter you can pass any JPanel object, so you dialog can display a lot of things.
The first parameter is the owner of the dialog, now I just set it to null, which means the dialog will have no owner. If you store a reference to your JFrame object then you can pass this for example and the dialog will always appear above your main window.
The last parameter is just for the general styling of the dialog. You can set it to other message types like ERROR MESSAGE too.
More info about displaying simple dialogs: https://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html
When using a screenreader, like NVDA, I want to be able to hear the text of the menu when I hover my mouse over it. I am able to hear the text when I push the buttons in the menubar, but not when I hover over them (the screenreader does reads the menu's of other programs when only hovering over the buttons).
I have set the AccessibleContext like below:
JMenu.getAccessibleContext().setAccessibleName("text");
JMenu.getAccessibleContext().setAccessibleDescription("more text");
I can set listeners to the objects that detects when a mouse hovers over them, but I do not know if/how I can cast a text to the screenreader to read. I tried ToolTipText, but that text is not read by the screenreader either. RequestFocus on the JMenu works, but setting the focus to an object just by hovering over it with the mouse provides other problems.
Does anyone knows how I can let a screenreader reads the JMenu-text when hovering with the mouse over the menubar?
I am using Java6 EE and the Java AccesBridge (version 2.02) on a Windows machine (XP and w7).
Swing is the weaker of the GUI technologies relating to accessibility in Java, compared to SWT at any rate. There's a few things you can try.
First is to make sure any accessibility fields are set (which you've started on). I can't remember if Java has an AccessibleRole field, but you can try setting that to menu and menuitem for your menu items.
Another thing you can try is the AccessibleMenu JMenu.AccessibleJMenu component. This one's the product of further reading, so I can't verify it from experience. But it and its surrounding classes may suit your needs.
If those don't work, you could try the option of talking to people's screen readers directly. Quentin C has a good library to do this, Universal Speech. I'm new to this library myself, but it does have a Java implementation in there that should show you how to use it in a Java program. Normally I wouldn't recommend this approach unless making the UI accessible really isn't working.
The last option would be to use the SWT components instead of the Swing ones, even if just for your menu bar. I wasn't sure how keen you'd be on this one, but it is an option and should resolve it.
I hope one of these suggestions helps you solve your problem.
So my situation is simple (IMHO):
I am trying to create web-esque Java application (it's a sort of Point-Of-Sale application) that behaves much like a website, but is all in Java. Right now I have a semi-simple SWT application written in Eclipse and it displays a few options (sign in, price check, inventory check and employee timeclock). When any of these is pressed (or corresponding keyboard shortcuts are activated) a dialog box pops up prompting authentication. Assuming user is verified, I want the main application window to display a new set of functions (scan item, item lookup, etc.) seamlessly.
If this were HTML I would just make a new page, and if I were writing against the Android platform I would just create a new activity...but this is very new and I am having a very hard time finding any relevant information.
PS I'm not set on SWT if anybody thinks a different library/technology (such as Swing/AWT) is better.
In SWT, if you want to replace the content of a Composite, you first need to dispose the existing controls, next you create the new controls, and finally call the layout(...) method on the Composite:
// Retrieve existing composite
Composite composite = [retrieve existing composite]
// Remove exising children
for (Control child : composite.getChildren()) {
child.dispose();
}
// Create new children
Label label = new Label(composite, SWT.NONE);
// Layout
// Maybe update the composite layout with composite.setLayout()
composite.layout(true, true);
Another solution is to use a Composite with a StackLayout if you want to display back and forth several predefined contents.
Whether you use Swing, AWT or SWT is entirely your choice. Personally, I prefer Swing, but you can do the same thing with SWT.
As for your predicament, you need to do a bit of studying regarding GUI's first. A Java desktop application consists of a top-level container, usually a JFrame (Window) that can contain other components, windows, dialog boxes etc. Your best best here is to pop up a MODAL dialog box that asks the user for authentication information. If the user is authenticated, you can dynamically create buttons, text boxes etc. in your code, creating the "new" look you want.
Might I suggest you start of with some simple GUI design exercises first, before diving into a full-fledged application? Consider the Java GUI tutorials at http://docs.oracle.com/javase/tutorial/uiswing/ as a good starting point.
Once you have mastered basic dialogue boxes, forms and components, you'd be in a far better position to plan your GUI and will find it easier to create it just the way you want it.
I have a ListSelectionDialog. Something like this for instance:
Now what I'd like to do is to have some items permanently selected and disabled (Basically I'd like to indicate to the user that these are part of the "core" selections and are not optional).
Is there a way to do this?
Unfortunately this dialog does not provide the functionality that you need. It uses the JFace CheckboxTableViewer to display the items, which does not support the "disabled" state of the check boxes very well (as of Eclipse 3.5). Furthermore this dialog is not intended to be subclassed.
the viewer used by this dialog is the CheckboxTableViewer.
You can try to add a checkstatelistener to cancel the unselection of the "core" selections.
Also you can use the method setGrayedElements to make them visually disabled.
I am not sure if this will give the wanted behaviour though.
I am working on a project that is using a JTable to display, among other things, a column of dates. We needed validation for the user input for dates, so I have implemented a combination of masking for format validation and parsing for actual date validation. I have done this using a custom CellEditor for the date column.
Inside my MaskedCellEditor, I have a JFormattedTextField. I setup the masking for dates. Then I add an InputVerifier to allow for actual validation. My InputVerifier implements verify() to check: 1. textField.isEditValid() 2. DateValidator.ValidDate(). If either is invalid, verify returns false and the InputVerifier locks the focus into the text field (the cell editor) and a small message dialog is displayed reminding the user of the date format.
The error message is a small, undecorated, non-modal, non-focusable JDialog that pops up underneath the cell being edited. It disappears on a keypress or a successful date verification. It is working great except for a small edge case.
If the user selects a menu button on the top of the application while an invalid edit has popped up the dialog, it switches screens, destroying everything currently on the screen (including the table). However, since the dialog is being shown and a keypress/successful edit has not occurred, the dialog is never hidden. It remains visible in a completely unrelated context on a different screen. Once the user has switched off the screen with the table, there is no way for the user to get rid of the dialog.
I have debated throwing either a Timer and/or a MouseListener on the dialog itself that would cause it to disappear, but I feel that I am ignoring the actual problem. The dialog is never being disposed of and I am pretty sure its because it is still set to be visible and it is preventing the garbage collector from getting rid of it.
I have a Cleanup method on the panel holding the JTable, but I cannot find a good way to reference the dialog (a component of the InputVerifier) in order to get rid of it. The dialog is pretty far removed from the table's parent panel. (Panel -> JTable -> CellEditor -> JFormattedTextField -> InputVerifier -> JDialog)
Any ideas on how to force the dialog to be hidden when the table is destroyed? If you need more details, let me know. I'm trying not to get you guys bogged down in the details, but there is a lot going on.
As a first thought, can you not go down the listener approach. If you have a closeErrorDialog() type method that gets called when upon successful valdiation, then you can also call it when a menu action is selected.
As an alternative, perhaps you could control the transition from menu to menu in some way, and create a "cleanup" method which will close down any exisiting error dialogs. This would allow for any other actions that need to take place when changing menus, to happen in the same place.
Just a couple of quick ideas of the top of my head. Hope they are along the lines of what you meant
Many people will vote me down for saying this, but it sounds like your dialog should be modal so that users can't switch away from it without dismissing it first. Or at least disable the menus that allow people to switch away while this dialog is displayed.