I want to write a text editor in JavaFX which acts similar to Eclipse/Netbeans IDE to highlight the Java code.
Can anyone suggest as to how it can be achieved or anyone has done this previously.
Thanks.
There's no pure JavaFX libraries for the code highlighting / editing as far as I know, so if you want to implement it in JavaFX you're going to be translating from a similar Swing (or other) project, or you're on your own.
However, you can use such a Javascript library and wrap it in a WebView if you want to achieve this - Jewelsea (who often swings by here) has done just this and explained it rather nicely here.
RichTextFX let's you specify style classes for ranges of text. Take a look at the Java keywords demo and its source code.
For any current searchers with this question, MonacoFX is a very nice, convenient, and EASY to use library that offers feature-rich code editing with at least 50 or 75 languages that it can properly syntax highlight, code fold, and all that good stuff. It is the same code editor that is used in the open-source version of Visual Studio. When I built my app and integrated MonacoFX, it was literally the most effortless portion of my project.
You can use eclipse text framework as posted
They also have a javafx code editor component called compensator
you can use intellij's swing code editor, with javafx swing interoperability
the component is com.intellij.openapi.editor.impl.EditorComponentImpl
you can check details running with intellij integrated ui inspector
Related
I need a new way to create the graphical user interface of my application. I don't want to use Swing. I'm looking for something that looks a little different. Can you recommend me some other way of creating it, please?
Why not JavaFX ?
It is supposed to be replacing Swing as the standard Java GUI builder, so it would be a good option as it will be getting regular updates from Oracle itself. Additionally, being an officially sanctioned kit, it has plenty of tutorials, guides, and a decent (and growing) userbase that you can use for help.
And it uses CSS, which is good to learn as it can be useful in other applications. (Webdesign, etc.)
Finally, JavaFX is included with Java 8, so you don't even have to worry about installing a separate package! (Although adding a package is really not difficult if you prefer Java 7 or below.)
If your complaint with Swing is how it looks, note that you can change the look and feel of a Swing application very easily, or even write your own if you really wanted.
To get a look and feel that matches other applications on your system, you call:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
At the beginning of your program.
The default L&F, called Metal, also has a couple themes you can choose from (or you can create your own):
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
Yes, javafx could be the way for you.
You can create Views using FXML files instead of coding everything in java.
The learning curve is not too hard in my view (and I am far from being a guru).
The tool Javafx Scene Builder is here to help you create your views or controls in FXML and integrates nicely with netbeans, and I suppose also with eclipse.
You can adapt the look of your controls using css.
I would suggest to start here to see if it would fit your need:
http://docs.oracle.com/javafx/2/overview/jfxpub-overview.htm
I usually write java code using a simple text editor and .bat files to compile and run. I'm not used to IDEs like Eclipse or Netbeans and as a result every GUI I've made so far has been written by hand.
Questions:
Can I use eclipse to build a GUI easily (e.g. drag-drop features)?
Can this generated code use only the basic java packages (swing, awt) and not any other package provided by the IDE?
I'm saying this because -correct me if I'm wrong- from what I have read so far, I understand that Eclipse and other IDEs use their own packages (to achieve better layouts for example). I would like to avoid this dependency and if possible copy-paste the code generated by Eclipse and then work in the simple way I'm used to.
Thanks in advance.
[edit]
Having tried it for a couple of days, I can now say that WindowsBuilder is exactly what I was looking for. Thank you for all your replies.
Eclipse uses the Standard Widget Toolkit (SWT, not included in JRE by default), Netbeans uses Swing (included).
Since recent Eclipse versions, it includes WindowBuilder to create Swing or SWT via drag'n'drop. WindowBuilder is even bidirectional, so code generation is supported as well as reflecting hand-made changes. It don't know if Netbeans includes this feature, too. In 'New' dialog of Eclipse you find everything you need under the WindowBuilder category.
Yes , You can use the feature of drag and Drop in java by going through these few Steps:
Help → Eclipse MarketPlace → WindowBuilder(Install)
Can I use eclipse to build a GUI easily (e.g. drag-drop features)?
Yes, go to the Marketplace and pull in WindowsBuilder; it supports bi-directional GUI drag-n-drop / direct-code editing.
Can this generated code use only the basic java packages (swing, awt) and not any other package provided by the IDE?
The code generated by the Swing Design tool is strictly Swing/AWT based.
It does offer design tools for SWT and GWT as well.
If you want to create Drag n Drop Swing GUI, you should try Netbeans. Eclipse may have a plugin but i usually find netbeans very good in GUI and it is also recommended by Sun for making Swing/AWT GUI
I haven't seen such in Eclipse. In Netbeans you can of course. But I am warning you! Create the GUI by hand. Netbeans is using GroupLayout to build drag and drop GUI, and that's a nightmare when you look at it!!! If eclipse has the same function, don't expect more than this!! Apart from that, not like .NET, most Java developers create everything by hand (Yes, real programming..That's why most say Java is hard). So, it is better if you can get used to it :)
I'm a .net developer and I am studying Swing for Java and I have a question.
Is there any way to build the form controls by dragging and drop like a simple .net windows application project or WPF project?
I am using eclipse and it seems that everybody works with controls by adding positioning and width, height by code, I find that a pain in the a**.
Yes! Take a look at Window Builder for Eclipse (install it from the update site). Netbeans has also a built-in editor, if you prefer that IDE.
You need to install a plugin to do that.
In Eclipse you can try WindowBuilder.
In Netbeans this ability comes within the standard package.
Java's Swing framework tries to address a broad set of platforms, and it does this by separating out look-and-feel concerns, layout concerns, etc. The most painful part of setting up a form is the layout, and that is driven by the LayoutManagers.
There are various LayoutManager implementations built to be used in conjunction with form designer tooling. I've personally had good results with IntelliJ's designer. See some screen shots and feature listings here.
I would personally not recommend using any Drag and Drop builders. In some IDEs the generated code is not editable. Some IDEs allow you to edit the code, but the bottom line is no matter what IDE you use the generated code is very difficult to maintain. After a while you will find it difficult to work with it yourself.
Instead, since you are just starting out, I would recommend using a good layout manager right away. While we are on that, give the jdk's layout managers a wide berth. They are horrible and that's what causes most people to go in for the drag and drop solution. Instead try the Jgoodies Form Layout. Its very easy to understand and use. The link is here:
http://www.jgoodies.com/freeware/formsdemo/index.html
After you have understood that, try to give this builder I wrote a shot. It makes life even more simple:
http://code.google.com/p/swingobjects/source/browse/SwingObjects/src/org/aesthete/swingobjects/view/SwingObjFormBuilder.java
Thanks for your answers to my previous question about GUI in java. I now wonder what are the solutions chosen by professionals to get a nice GUI, for "real" applications. Do you use swing and JComponents and just change the "look and feel" ? Do you prefer awt or another library ?
Sorry if that question sounds weird, I'm a student and I don't really know how java is used in the real world...
In our company we use Swing, as that is supported by the JVM out of the box, but we do use color coded background colors for some panels and buttons.
If we'd use something different, like SWT or Jambi we'd also have to roll out those frameworks for all platforms, and test those frameworks for all OSses and (supported) java versions. Not nice at all.
It is however fairly tricky to create a nice responsive application with Swing; so you really need to use SwingWorker and the like. With a bit of experience however you can create a nice application that way.
And even if it isn't the fastest framework to develop in, development time is really small compared to defining the functional requirements of the user interface, and testing and support when the version is released.
That said, our target is desktops. If you target mobile devices or also need a web frontend your choices may vary.
I don't believe anyone prefers AWT anymore. Swing supplanted it entirely eleven years ago, building on top of it to correct flaws in the AWT 1.0 design.
Swing isn't the only way that professionals make Java UIs. That works for desktops, but there's also JavaFX now. For the web, UIs are built using HTML, CSS, JavaScript, and JSPs.
My experience is that most organizations that want to create rich GUIs still use Swing, and manually go through all the annoyances of layout managers, etc.
The use of SWT is fairly limited to organizations that are using the Eclipse RCP as their platform. I'm not sure why it hasn't caught on outside this platform.
It's sad to admit, but Java Swing GUIs don't generally look good unless you spend a lot of time creating a more native feel for them. Even then, they often lose out on aesthetics to equivalent programs written specifically for Windows and which use Window APIs like WinForms.
The most decent Apps I saw in the last years were build using Eclipse Rich Client Platform
Eclipse uses the Standard Widget Toolkit
and provides Graphical Editing Framework (GEF)
We typically use Swing becuse it's supported in standard JREs out of the box. Normally we do the initial form design and event hookup in Netbeans and then export it to whatever we wish, Eclipse, for example.
Netbeans spits out pure Java using standard libraries (plus a jar or two you have to include) so it's no big deal designing the form in Netbeans and later moving on to something else.
Some people suggested doing form layout by hand using a layout manager. I see that as an option only if you are doing something big and very well budgeted that has to be maintained ad infinitum. Otherwise it's just too time consuming to be worth it.
We rely on SWT for our Java GUIs. Yes, you have to include an external native library, but the look and feel is native, more responsive (although Swing has become much faster in the past few years) and seamless with other apps on the target platform.
Macintosh OS X creates their own Java runtime. They give Swing components the same look and feel as native applications.
I use strictly Swing. I distribute "real" desktop applications via Web Start for both Mac and Windows that interface with the user's smart card reader.
The NetBeans IDE gives you a WYSIWYG way to create your forms. I've tried it out, and it's pretty neat, but we still use Eclipse as our IDE and design the forms in code.
Is there a plugin that would allow me to design the GUI in eclipse or netbeans and then extract the source code to be used in another environment?
I am much more comfortable using emacs for my development but gui design is much easier with a WYSIWYG environment. What i am looking for is design the frame in eclipse/netbeans and then extract just gui code so i can import it to my project?
Like JFrameBuilderdoes.
What's wrong with using both Netbeans/Eclipse and emacs on the same set of files?
Use Netbeans or Eclipse to design GUI.
Close Netbeans/Eclipse.
Open Emacs and code away.
Close Emacs.
Rinse and repeat.
Personally, what I have experienced is that GUI design in Swing is best done without a WYSIWYG. I came into Java after many years of developing applications with Delphi, and at that time there was no suitable GUI designer for Swing, which was a bit of a shock for me.
In order for a manual UI design/coding to be efficient a really good layout manager should be used. MigLayout is one of such layout managers. Since I've started using it I have never looked back at WYSIWIG tools -- a sheet of paper, a pencil, MigLayout and a full control over your code.