Sei sulla pagina 1di 9

VladislavKoreck

Ncoomn
Search

Home Eclipse HowtoEclipse+JavaFX+fxml+SceneBuilder(WYSIWYGdesigner)

HowtoEclipse+JavaFX+fxml +SceneBuilder(WYSIWYG designer)


Publishedon26October,2012byVladislavKoreckinEclipse,Java

Language
English esky

Categories
(K)UbuntuLinux AsusK52F AsusN53SV C#.NET Eclipse FedoraCore Java JavaFX

SinceJDK7u6isJavaFX2integratedtoJavaSEonallmajor platforms(Windows,LinuxandMac).Ithinkthatitistimetostart switchfromSWINGtoJavaFX. IuseEclipse4.2onUbuntu12.1064bitwithWindowBuilderPro installedforSWINGWYSIWYGdesign,butthereisnopluginwith JavaFXGUIdesigner.Dontworry,thereissolutionwithusing e(fx)clipseandJavaFXSceneBuilder. WewilldevelopJavaFXexamplewithusingGUIdesignerandEclipse inthispost.

Prerequisites
Wehaveinstalledincomputer: LatestJDKwithJavaFXsupport Youcandownloadithere: http://www.oracle.com/technetwork/java/javase/downloads/jdk7u9 downloads1859576.html Eclipse4.2JunoJEE Youcandownloadithere:http://www.eclipse.org/downloads/ e(fx)clipseplugin inEclipse4.2JunoJEE Thereistutorialhowtoinstallthispluginwithalldependencies: www.korecky.org/?p=650 JavaFXSceneBuilder Iusebetaversion: http://www.oracle.com/technetwork/java/javafx/downloads/devpreview 1429449.html

JBoss OpenSUSE Sharepoint MjROV Projekty GNoteDigitalOrganizer SharePoint2007javalibrary Linuxahry Nezaazen

Eclipseconfiguration
WehavetointegrateJavaFXSceneBuilderintoEclipsefirst. 1. RunEclipse

2. MenuWindow/Preferences 3. General/Editors/Fileassociatonsintree 4. Select*.fxmlfromfileextensionslist 5. ClickbuttonAddinAssociatededitors

6. ClickExternalprogramandselectJavaFXSceneBuilderfrom listofexternalprogramsorclickBrowseandfindprogram launcheronthedisk.

7. SelectJavaFXSceneBuilderinAssociatededitorsandclick buttonDefault.JavaFXSceneBuildershouldbeadefault editorforFXMLnow.

JavaFXExample
Weareready,letscreatesimpleJavaFXapplication. 1. CreatenewJavFXprojectandcreatepackage org.korecky.javafxexample(oranother,dependsonyou)

2. CreateMainForm.javaclassandimplements javafx.fxml.Initializableinterfaceinpackage org.korecky.javafxexample(orinyourpackage).Codesouhld look:


p a c k a g e o r g . k o r e c k y . j a v a f x e x a m p l e i m p o r t j a v a . n e t . U R L i m p o r t j a v a . u t i l . R e s o u r c e B u n d l e p u b l i c c l a s s M a i n F o r m i m p l e m e n t s j a v a f x . f x m l . I n i t i a l i z a b l e { @ O v e r r i d e p u b l i c v o i d i n i t i a l i z e ( U R L l o c a t i o n , R e s o u r c e B u n d l e r e s o u r c e s ) { } }

3. CreateMainForm.fxmlJavaFXMLfileinpackage org.korecky.javafxexample(orinyourpackage)

4. EclipseshouldautoopenyourMainForm.fxmlinJavaFXScene Builder

5. SetControllerclassinCodepaneltoyourMainForm.java,in mycaseorg.korecky.javafxexample.MainForm.Itisvery important,thisstempconnectyourJAVAcodewithFXMLform. 6. DraganddropButtonfromLibrarytoyourforminscene builder.Andsetbuttonproperties:


f x : i d = b t n P r i n t H e l l o T e x t = P r i n t H e l l o

(http://www.korecky.org/wpcontent/javafxexample05.png) 7. DraganddropTextFieldfromLibrarytoyourforminscene builder.Andsettextfieldproperties:


f x : i d = t x f H e l l o

(http://www.korecky.org/wpcontent/javafxexample06.png) 8. Savefileandclosescenebuilder 9. LetsfinishbindingbetweenFXMLandourjavaclass.Create instanceofeachcontrolbyaddinglinelikethisone:


@ F X M L p r i v a t e T e x t F i e l d t x f H e l l o

txfHelloisfx:idofreferencedcontrol. CompletecodeofMainForm.java:

p a c k a g e o r g . k o r e c k y . j a v a f x e x a m p l e i m p o r t j a v a . n e t . U R L i m p o r t j a v a . u t i l . R e s o u r c e B u n d l e i m p o r t j a v a f x . e v e n t . A c t i o n E v e n t i m p o r t j a v a f x . e v e n t . E v e n t H a n d l e r i m p o r t j a v a f x . f x m l . F X M L i m p o r t j a v a f x . s c e n e . c o n t r o l . B u t t o n i m p o r t j a v a f x . s c e n e . c o n t r o l . T e x t F i e l d p u b l i c c l a s s M a i n F o r m i m p l e m e n t s j a v a f x . f x m l . I n i t i a l i z a b l e { @ F X M L p r i v a t e T e x t F i e l d t x f H e l l o @ F X M L p r i v a t e B u t t o n b t n P r i n t H e l l o @ O v e r r i d e p u b l i c v o i d i n i t i a l i z e ( U R L l o c a t i o n , R e s o u r c e B u n d l e r e s o u r c e s ) { b t n P r i n t H e l l o . s e t O n A c t i o n ( n e w E v e n t H a n d l e r ( ) { @ O v e r r i d e p u b l i c v o i d h a n d l e ( A c t i o n E v e n t e ) { t x f H e l l o . s e t T e x t ( " H e l l o ! " ) } } ) } }

10. WehavetocreatenolastclassforrunningourJavaFXscene. CreateJavaFXMainClassnamedMain.javainpackge org.korecky.javafxexample(orinyourpackage)

WewillopenourMainFormbyaddingtheselinestomethod startintheclass.

P a r e n t r o o t t r y { r o o t = F X M L L o a d e r . l o a d ( g e t C l a s s ( ) . g e t R e s o u r c e ( " M a i n F o r m . f x m l " ) ) } c a t c h ( I O E x c e p t i o n e ) { e . p r i n t S t a c k T r a c e ( ) r e t u r n } S c e n e s c e n e = n e w S c e n e ( r o o t ) p r i m a r y S t a g e . s e t S c e n e ( s c e n e ) p r i m a r y S t a g e . s i z e T o S c e n e ( ) p r i m a r y S t a g e . s h o w ( )

CompletecodeofMain.java:

p a c k a g e o r g . k o r e c k y . j a v a f x e x a m p l e i m p o r t j a v a . i o . I O E x c e p t i o n i m p o r t j a v a f x . a p p l i c a t i o n . A p p l i c a t i o n i m p o r t j a v a f x . f x m l . F X M L i m p o r t j a v a f x . f x m l . F X M L L o a d e r i m p o r t j a v a f x . s c e n e . P a r e n t i m p o r t j a v a f x . s c e n e . S c e n e i m p o r t j a v a f x . s c e n e . c o n t r o l . B u t t o n i m p o r t j a v a f x . s c e n e . c o n t r o l . T e x t F i e l d i m p o r t j a v a f x . s t a g e . S t a g e p u b l i c c l a s s M a i n e x t e n d s A p p l i c a t i o n { @ O v e r r i d e p u b l i c v o i d s t a r t ( S t a g e p r i m a r y S t a g e ) { P a r e n t r o o t t r y { r o o t = F X M L L o a d e r . l o a d ( g e t C l a s s ( ) . g e t R e s o u r c e ( " M a i n F o r m . f x m l " ) ) } c a t c h ( I O E x c e p t i o n e ) { e . p r i n t S t a c k T r a c e ( ) r e t u r n } S c e n e s c e n e = n e w S c e n e ( r o o t ) p r i m a r y S t a g e . s e t S c e n e ( s c e n e ) p r i m a r y S t a g e . s i z e T o S c e n e ( ) p r i m a r y S t a g e . s h o w ( ) } } p u b l i c s t a t i c v o i d m a i n ( S t r i n g [ ] a r g s ) { l a u n c h ( a r g s ) }

11. LetsrunourMainclassandclickonbuttonPrintHello!

DownloadEclipseproject
YoucandownloadthisexampleascompleteEclipseprojecthere (www.korecky.org/Downloads/JavaFxExample.zip). Relatedposts: 1. HowtocreateApacheMavenprojectwithJavaFXandFXML support 2. InstalaceEclipseaJBossTools 3. InstallationofEclipseHeliosJEE64bitandpluginsforJava development 4. MTOPpluginyproEclipseJEE 5. Eclipse4.2JunospodporouprovvojJavaFX,GoogleWeb Toolkit,Adnroid,JavaSWING,Subversion 6. InstalaceJBossAS5.1naFedoraCore13 7. JBoss5.1ASJDK6instalaceJBossESB 8. JBoss5.1ASJDK6instalaceJBossRiftSawBPEL 9. NstrojeprovvojclientaWebovchslueb 10. Javazsknsprvnchsystmovchbarev

Curtir Uma pessoa curtiu isso. Seja o primeiro entre seus amigos.

Tags:Develop,Eclipse,Java,JavaFX,Programovn

Eclipse4.2Junospodporoupr... HowtocreateApacheMavenpro...
NoComments

LeaveaReply
Youremailaddresswillnotbepublished.Requiredfieldsaremarked *
Name*

Email*

Website

Comment

YoumayusetheseHTML(HyperTextMarkupLanguage)tagsand attributes:< a h r e f = " " t i t l e = " " > < a b b r t i t l e = " " > < a c r o n y m
t i t l e = " " > < b > < b l o c k q u o t e c i t e = " " > < c i t e > < c o d e > < d e l d a t e t i m e = " " > < e m > < i > < q c i t e = " " > < s t r i k e > < s t r o n g > PostComment

Notifymeoffollowupcommentsbyemail. Notifymeofnewpostsbyemail.

RecentPosts
HowtocreateJavaFX FXMLcustom component HowtocreateApache Mavenprojectwith JavaFXandFXML support HowtoEclipse+JavaFX +fxml+SceneBuilder (WYSIWYGdesigner) Eclipse4.2Junos podporouprovvoj JavaFX,GoogleWeb Toolkit,Adnroid,Java SWING,Subversion Kubuntu12.10Quantal

RecentComments
PeteronOpenSUSE 11.1Subversion server+Apache2 VladislavKoreckHow tocreateJavaFXFXML customcomponenton HowtocreateApache Mavenprojectwith JavaFXandFXML support FabrionKubuntu12.10 QuantalQuetzal64bit osobninstalan pruka IvanBellanonGNote DigitalOrganizerPrvn

Tags
.NET ApacheAsus

N53SVC#Debian

Develop
EclipseFedoraCore
GNoteDigitalOrganizer Games

GnomeGNU/Linux
HardwareHry

Java

JavaFXJBoss

KDEKDE4

KubuntuMOSS

Quetzal64bitosobn instalanpruka

oficilnverze MPonMjROV Zkladnkoncept

OpenSUSE
Oracle

Programovn
ProjectsProjekty roboticsrobotikaROV SharePointSSDSVN

UbuntuVMware
VPNWSS3.0

x86_64
VladislavKoreck

Ncoomn