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.
Related
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.
I have list of objects which I want to display in GUI.
Each object is:
1) complex (it has a number of fields), thus I need several widgets to be used in GUI component which corresponds to 1 model object,
2) editable. Its properties can be changed by user via GUI (buttons, input fields and checkboxes which lay within component which corresponds to 1 model object).
How conceptually can I do this? Which UI framework and which widget to use?
Coming from android development, I have no experience in java desktop applications (by the way, in android this task can be easily accomplished by means of standart instruments (listview + its adapter)).
I have tried swing framework with its JList and JTable. But it turned out that elements within JList's cells are not editable (say, I cannot press buttons if there are a few inside Jlist's cell). The same applies to JTable.
I have googled for swing, swt, javafx etc, but didn't find direct answer how this task can be accomplished.
Any help is appreciated.
P.S. It is not an option to use JTable with several columns. In fact, I want to have list of JForms or JPanels (in swing terms).
I am writing a GUI app in WindowsBuilder eclipse java and have some questions:
I have a check button that if it's checked some controls are enabled. Is there an elgant way to allow all of them by one command? I mean that I dont want to enable them one by one, just enable them at once - is it possible to define a logical group that will allow me to do it?
Is there any common design pattern to write Java GUI applications?
I am new in Java, so will appriciate any guidance in these queastion.
Thanks!
There is no build-in function to check/uncheck them all with one command.
The "easiest" way that comes to mind is to store them all in a List and create a function that iterates over that list and checks/unchecks everything.
private List<Button> buttons = new ArrayList<Button>();
// ADD YOUR BUTTONS
private void setSelectionForButtons(boolean enabled)
{
for(Button button : buttons)
button.setSelection(enabled);
}
Then you can check/uncheck them all by calling:
setSelectionForButtons(true);
or
setSelectionForButtons(false);
As for the "design patterns": There is an excellent tutorial for writing SWT applications here.
This is a crosspost to the thread in Javaranch (includes some images): http://www.coderanch.com/t/567472/GUI/java/Optimal-solution-creating-multiple-dialog
I'm trying to develop a simple swing desktop application where I imagine alot of different dialog's jumping around to fetch user input. Would need to present labels, textfields, passwordfields, combobxes, checkboxes etc in various dialog windows.
For example: creating the database firsthand, creating the first admin account, adding users, changing user accounts etc.
I have an understanding that JOptionPane is used to create simple quick & easy modal dialog's. I would really like to know why one would choose one over another in this case. Which one is more preferable to use: JOptionPane vs. JDialog
Also I could use some pointers how one should appropriately design and implement this.
Thank you.
Here's a statement I found on the Java website that says one key point about the difference between the two.
How to make Dialogs
A Dialog can be modal. When a modal Dialog is visible, it blocks user input to all other windows in the program. JOptionPane creates JDialogs that are modal. To create a non-modal Dialog, you must use the JDialog class directly.
So it sounds like you would use JOptionPane if you want a user to have to make a choice and close the box before returning to the main screen. If you use a JDialog box, then they can just click around it and get back to the main screen without making a choice. For example, say you wanted to make a user choose the number of results before clicking submit, you wouldn't want them to be able to click around that window and click submit. You would use JOptionPane to force them to select a value first before going back to submit.
Check out http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html it pretty much has everything you would need.
As i understand it, JOptionPane is great for what it can do, but you can't really change the functionality beyond that (not easily). JDialog is better to inherit from if you want to create your own custom Dialogs.
I'm creating a standalone SWT desktop application that has around 10 different screens (few wizards, help, forms, etc). Some elements on screen don't change at all (like header, background, etc) and there is a working area that changes depending on what is clicked, etc.
What is the best way to manage application screens? Do I need to create all screen at startup and then show/hide them depending on what is clicked? Or do I need to create those screens dynamically?
Also, I couldn't find any way to show/hide a Composite, do I need to dispose it and then create again?
What is the best practice? I'm new to SWT developing outside of Eclipse so any help would be beneficial.
Deciding whether to create screens up front or creating them the first time they need to be displayed is a decision that needs to be made on a per application basis. If there is a good chance that all the screens are going to need to be used on a particular application run and the number of screens is low (10 screens is relatively low) then you may want to create them at application startup so the UI is snappier once the application loads.
If you use bindings then you may need to come up with a dispose strategy (even if you only dispose the bindings) so you don't have too many events flying around.
Control has a setVisible(boolean) method (and Composite inherits from Control) which you can use to show and hide a component. Note this will only prevent the composite from being shown on the screen, the layout manager will still allocate a blank space for it. Many SWT layouts have a way to exclude a control from the layout which will get rid of the blank space. For example if you are using GridLayout then you would set the exclude variable on you GridData object to true when you hide that control.
Another option is to use StackLayout. This lets you stack a bunch of Composites on top of each other and then choose which on is on top. This might be a good fit for you if you have static areas plus a working area like you described. I would put the header, footer, and an empty composite with a StackLayout in a class file. I would then put each screen that will be displayed in the working area in their own classes. You can either have these screen classes extend Composite and then set up themselves in the constructor or you can use a factory method to setup the screen. Either one is a common and acceptable practice and comes down to a matter of taste.