Can we assign both classes and id to Javafx Controls - java

Hi there JavaFx community. So I recently shifted from html/javascript to Javafx and using scene builder to create my UI.
My question is, like in html we could assign classes and id to an element, can we do the same in JavaFx, ie assign multiple textfields and buttons the same class? According to what I have seen we cannot assign classes in javafx. I would appreciate if someone could shed some light on it.
I am asking this as having classes for GUI elements in html makes life so much easier so I'm just dumbfounded if javafx doesn't allow us to do this.
Also in that case, what would be good alternative ways around this issue.
Thanks heaps..

You can define css classes in JavaFX just like you can in HTML. Have a look at this tutorial: http://docs.oracle.com/javafx/2/css_tutorial/jfxpub-css_tutorial.htm See: "Creating Class Styles"

Related

Grids in Java- Equivalent

Is there any grid equivalent object in java ?
I tried using j tables but they don't have all the functionalities needed.
in C# there is a grid object which saves a lot of work. i was wondering if there is any similar object in java.
As far as I know, there is no grid like data structure or collection available in Java. Though you can implement a grid like structure in Java with help of a two-dimensional array.
In case of AWT you might want to use the GridLayout class. Hope this helps.
Definitively the equivalent is JTable, however, if you're trying to create functionalities seems to Grid in C#, you will need to do a little bit extra effort, with swing you should focus on events and add the corresponding listeners in order to add the desired features on it.

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.

How do i format a specific word/sentence inside jeditorpane?

I am not a java expert. Just learning as i go.. This is my way! I am now designing a IDE for C++ (just fun, not professional) . I have the project almost ready, now i want to add some text highlighting function to the IDE. For example i want the IDE to recognize a predefined set of words and color them green,red. How do i do it?
You could use HTML, but you probably would be better off using the TextAction methods for a JEditorPane.
Another alternative is the StyledDocument interface.
Added because of the comment: You can use the StyledEditorKit class to see implementations of TextAction.
Here's Oracle's tutorial on How to Use Editor Panes and Text Panes.

Working in java image

I will explain my question clearly.
I need to zoom in/zoom out the world map.
When I click on the particular country in map, control should redirected to new page with respective the country.
I dont have any idea about this in java. Please explain the steps to acheive the above task.
As the question is quite general, here is a general answer: Zooming often means, that you want to display a certain percentage of somethin, and not the whole, where your size of the displayed will not change.
But in your case it seems more like a "find a mouse click in a polygon" thing. So you have to add a selection/click listener to whatever widgets you use (Swt? swing? ....?) where you change what your program renders.
It sounds like you may be trying to reinvent the wheel. Google etc have already solved this problem rather well. It might be better to incorporate an existing solution into your application. Have a look at GoogleEarth inside Java Swing.

Drag and Drop and identify locations with java

I'm trying to do something quite simple, but I'm having a hard time finding good examples on the net to what I want specifically.
I'd like to somehing very similer to what it's here:
Dao
It's a simple game called DAO and I just need to have a background image with 16 squares (4x4) and drag and drop the images (pieces) on each square to the others. I'm developing the interface using swing and I simply want to know a good place to find tutorials for such implementations or a simple suggestion on how to do it.
Thanks in advance
Shameless plug:
have a look at my simple example via my google project
http://code.google.com/p/jchronos/
There is code to drag list item across list boxes. Same should be applicable to JLabel
Look at sources
http://code.google.com/p/jchronos/source/browse/trunk/src/org/jchronos/ui/QuadrantPanel.java
http://code.google.com/p/jchronos/source/browse/trunk/src/org/jchronos/ui/ArrayListTransferHandler.java

Categories

Resources