Form handling in net beans desktop applications - java

hello I have a basic Java ability when it comes to writing code and creating such things as calcs and booking system, I am wanting to use the Desktop application in netbeans for a more professional look but I carnt manage to switch between visual forms i have created using buttons, in vb I would just set the form as me.visible(False) and Form2.visible(true). Any ideas guys thanks

Well it is very similar in Java too instead of typing
MyForm().visible(true)
Use
MyForm().setVisible(true);
Basically if you clicked a button and you wanted a new form to be displayed it would look something like
private void jButton1ActionPerformed(ActionEvent evt)
{
new TestForm().setVisible(true);
}

Related

How to get the text input in javafx using controller class?

I am new to javafx and building an java application using it with eclipse IDE. I learned how to create a main fx class and user interface with Scene builder. The main problem is i dont know how to get the user input (from the text field or from text area ) and display that text on console output or save that text into database after clicking 'save' button.
i want to know how can do above tasks using controller class in eclipse.
Any help would be appreciated and Thanks in advance.
I advise you first to learn the JavaFX without (FXML/Controller) and for your question :
//Event when button clicked
yourButton.setOnAction(evt->{
//display the text of your textField on the console
System.out.println(yourTextField.getText());
});
As for the Button with a Controller, you have to separate your program into two parts (View FXML |Controller java ). The official documentation explains it very well here, good luck !

Eclipse Scout (re-)activate Form in SWT Client

yet a new Eclipse Scout question from me:
In my Scout Application which is roughly based on the template "Outline Tree and Table Form" I managed to add new instances of a (search)form with a click on a node. My form's display properties are configured like this:
#Override
protected int getConfiguredDisplayHint() { return DISPLAY_HINT_VIEW; }
#Override
protected String getConfiguredDisplayViewId() { return VIEW_ID_PAGE_DETAIL; }
I'm not adding the forms to pages with the built-in methods(e.g. setDetailForm(IForm form)), but I set them as a new attribute to the pages and start them via their FormHandler. In this way I achieve that the Scout renderer tabs the forms next to each other and this is exactly what I want. Adding them as forms to the page causes the renderer to close the other forms whenever a page is activated, so only one form is displayed at one time.
My problems with this implementation are:
Reactivation of the tabs is only possible in the RAP client. For the RAP client it is enough to call the activate() method of the form to reactivate and focus the corresponding tab.
On the other hand the SWT client (which I depend on) doesn't seem to care at all about the activate() call and therefore does not reactivate the page.
So I'm searching for a safe and easy way to persuade the SWT renderer of
tabbing the forms next to each other preferably without the use of a Scout TabField. As described above, this is already working, but I'm not sure if this is the recommended way.
reactivate the tabs on a NodeClick as the RAP client already does
Receive events when clicking on the tab closing the tab (X-button in SWT, no button in RAP -.-), or whatever. I think this question is bit broader as it is a general problem in Scout to step into product-specific processes which are not part of the abstract programming model of Scout. Nevertheless, it would be nice to process those event and others out of the global client without tweaking the specific rendering products.
A screenshot of my program's UI to make things easier to follow:
In the screenshot the fifth form is activated as a view and the corresponding node in the outline tree on the left is also marked. As you see, there are multiple forms added which all belong to a node in the outline tree. When I click a node in the tree, I want the corresponding form to be activated and focuse if it hasn't been openend before. Apart from that the tabs should stay the same. I don't want to reinitialize the forms that already exist.
I'm using Scout Version 5.0
The RAP UI is nearer to the SWING UI than to the SWT. This is why, out of the box, the views can not be closed with the x in RAP (similar to Swing).
For SWT we rely on the workbench provided by the Eclipse Platform. This defines how views are opened and tabbed in a View Stack.
For me it is Ok to use scout (SWT renderer) that way. Here an example:
The ComplexForm is opened as a SWT View next to the already opened Form.
I am surpised to hear that activate() on the scout Form doesn't work for you. I had a similar problem, raised Bug 433010 and we decided to close it, exactly because the activate() method was the solution.
ComplexForm form = new ComplexForm();
form.startNew();
form.activate();
I guess that on any event (a click somewhere on a Menu or on a Node) you can get call activate() on the form instance.
Which version of Scout are you using?
Maybe you could add a Screenshot in your question, because I am missing your point.

Collect Input from a Java JTextarea

I'm working on one of my first java applets and I want to start of fairly simple (though I have a good understanding of how code works I dont know much in terms of what methods I all have at my disposal when using java)
I have created a Jframe window that has a JTextarea in it. I would like to execute certain lines of code when certain things are typed into this box. In essence, its a simple text input system. How would I go about doing this or is there a better component to use for this?
in addition to getText(), for JTextField some prefer the getDocument() method. In Java, Listeners are used to capture events, such as "what was typed to the text area". This tutorial will get you started, if you have trouble implementing you can come back with a more specfic question and some code :)

Programming with a Java MVC approach using NetBeans GUI builder

I've been tasked with making a GUI that essentially takes a bit of user input and does some folder/file manipulation on various drives accessible by the machine the program is being run on. While designing this GUI, I'm starting to realize that MVC will make my life much easier and anyone else who decides to modify code, but I can't really see how this can be done via NetBeans.
I've done a bit of reading up on this topic, and I can't really see any clear cut answers as to whether or not this can be done on NetBeans. Surely it can be done if I programmatically build the GUI, but that somewhat defeats the purpose of why I chose to use NetBeans.
Netbeans is fine to do this.
The key thing to realize is that while all of the basic Swing components are MVC, for the most part you don't interact with them that way. A simple text field has it internal model, but that model isn't your model, the text field is more a primitive.
Your model deals with higher level events (button actions and what not), rather than button presses and arrow moves and mouse clicks.
So, for high level MVC, the primary mechanism of communication is through PropertyChangeListeners. And the basic task of building your app up is wiring the PCLs of the assorted data elements along with their GUI components together.
For example, a simple case is you have a list of items. And that list is rendered on the screen via a JTable, and that table is on a JPanel.
Your list has it's own model, i.e. it's not simply a Java List. It's not a List because standard Java Lists don't support PCL notifications. But your Model would obviously wrap such a List.
Now, the next question is how do you wire up JTable to be associated with your List model.
One, you could subclass JTable and bind it to your Model. Or, more simply, you use the JTable as a primitive, and let the enclosing JPanel manage the interaction between your Model and the JTable.
That means having your JPanel implement PropertyChangeListener, and then, when wiring everything up, you do something like this:
ListModel myModel = new ListModel();
ListPanel myPanel = new ListPanel();
myModel.addPropertyChangeListener(myPanel);
Now, whenever your ListModel is changed, is will notify the ListPanel.
On your ListPanel you can having something like:
#Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(ListModel.CHANGED)) {
ListModel model = (ListModel) evt.getSource();
DefaultTableModel tm = (DefaultTableModel) listTable.getModel();
tm.setRowCount(0);
for (String s : model.getList()) {
tm.addRow(new Object[]{s});
}
}
}
Now, you can see this simply reloads the entire table model, but you can make your property changes as fine grained as you want. You can also see that if this was some other model (like a Person or something) you can populate individual text fields and whatnot on the panel.
This is a pretty simple GUI, but it shows the fundamentals of how this all wires together. I think a bit of this is lost in the Swing examples which are great for one panel screens but don't scale at all when you start adding other views.
Your JPanels basically become combined VC, as your GUI gains complexity you can factor those kinds of things out, but its works pretty well for reasonable amounts of screens and such.
There are two ways in which Netbeans can help you leverage its codebase: GUI Builder (1) and NB Platform (2).
(1) Netbeans had for a while one of the better drag-n-drop GUI builders in the Java world, codenamed Matisse.
That said, it's been a long time since I worked with it - and I never really liked the generated code, it wasn't very comprehensible (which of course is not the purpose of auto-generated code). For more complex UIs we hand-wrote the layout and the work was bearable, even if not the most pleasant. For simple UIs, I'd try GUI Builder again, for complex UIs with a lot of wired logic, I'd probably still would write it by hand.
To see how the GUI Builder works, take a look at one of the many tutorial videos, e.g. this one:
NetBeans GUI Builder: Adding Components
(2) Netbeans Platform is to Netbeans, what RCP is to Eclipse. A rich set of components developed for an IDE, that can be reused. I briefly looked into NB Platform and we would have used it, if the project didn't change course. Maybe this SO question can shed more light on this aspect: Which Rich Client Platform to use?.
Concerning MVC. There was JSR 296, a generic Swing Application Framework, that looked somewhat promising, but was withdrawn in 2011. That did not stop people to fork it and work on it, as this project shows: Better Swing Application Framework, with a release in mid 2012. Even if you do not use such a framework, please do not put all code in one class (as you mention in you comment), but create a simple model/controller and keep the UI components separate. It does not need to be fancy for a simple app, a minimal MVC-ish separation of concerns might suffice.
I also hit this problem and i found a link which gives a good example how to seperate the controller from the view using the NetBeans GUI builder.
Here is the link.

Multiple Page Development in Java with Eclipse and GWT

I have been writing some basic code for an application I am designing. I have learned the basics and gotten some simple database connection working with RPC calls etc. What I need to do now and am completely lost (as I am traditionally a c# developer with windows forms).
In c# if I wanted a new form I would just create it, and then call the show method.
How does one create multiple pages in GWT, and switch between them?
Thanks in advance,
Chris
The simplest way would be to
Make a new java class (GwtHome.java, GwtHelp.java etc)
Extend these classes by using the Composite class
Make the equivalent of a Master Page and add it to the rootPanel as a class with the appropriate headers, menu, footer and Content Placeholder (Could be any of the AbsolutePanel, VerticalPanel, HorizontalPanel objects provided by the GWT Framework)
By clicking on the menu clear the Placeholder and add the appropriate object of GwtHome, GwtHelp etc.
After getting aquanted with the above procedure, you might want to break up the code in many files using a design pattern as suggested by Andrei.
Simply clear the root panel (RootPanel.get().clear()) and add the widget for your new "page", the same way you added your first one.
If you're using LayoutPanels, do RootLayoutPanel.get().clear() instead.
Look at Activities and Places design pattern: https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces
I highly recommend it for a multipage GWT app. It explains pretty well how you create different "views", that are driven by their "activities", and tied to specific "places" (pages) that users can navigate.
Typically you use a LayoutPanel as your "page" container that occupies the entire available browser window. You split this LayoutPanel into 2-3 layers (zones), like top menu, side menu, main area. Each area contains one widget, usually a ScrollPanel, FlowPanel, or HtmlPanel. Then you use different widgets or HTML inside each of these widgets to display whatever you need. You may also create your own composite widgets that you can reuse in different pages.

Categories

Resources