Tag Archives: Swing

Using JavaFX Chart API to add charts to Swing applications

Using JavaFX Chart API to add charts to Swing applications
// Kogonuso

By Mohamed Sanaulla

In our previous post we looked at how we can embed JavaFX components into Swing applications. As Java Swing lacks Charting API, we can make use of the JavaFX Chart API and not depend on other 3rd party libraries like JFreeChart and others. The javafx.scene.chart is the package which contains all the charting related classes. In this example we will look at creating Scatter Charts and Bar Charts which are categorized as XYCharts which is nothing but these charts are plotted on a X and Y axis. The classes for the charts to be used are javafx.scene.chart.ScatterChart and javafx.scene.chart.BarChart. If you happen to look at the declaration of these classes, they accept generic types where X indicates the type on the X Axis and Y indicates the type on the Y axis. These charts require a set of axis to be defined before they are used. If the axis is of type Number, then one can use NumberAxis and for String values one can make use of CategoryAxis. For each of the Number axis or category axis we can define the range of of values to be plotted on the axis. Let me show some code on how it can be achieved:

Java GUI – JavaFX drawing function

When I started learning about how to make a simple GUI there was actually no dilemma. Java Swing  was buried deep in the ocean of neglected libraries, to reside side by side with Win 3.11…okay, not that far, but the point is the same. No one sane uses Java Swing anymore, at least he/she shouldn’t. JavaFX […]


Desktop Java Tutorials

Desktop Java Tutorials

Youtube [Back to Top]
Swing [Back to Top]
Xuggler [Back to Top]
JavaFX [Back to Top]
JavaCV [Back to Top]

Simple JavaScript OOP for C++, Java and C# Developers

via GUI, GWT, GXT, SmartGWT, GWT-Ext, JAVA SWING, C++/C#: Simple JavaScript OOP for C++, Java and C# Developers.

Most developers are familiar with object-oriented programming and design in languages like Java, C++ and C#. JavaScript, however, does not provide any obvious means to support this kind of object-oriented development. The result is that structured code becomes very hard to write for developers new to the world of JavaScript.

If you have written a few programs in JavaScript and wondered if it’s possible to add more structure to your programs using object-oriented strategies, this tip is for you. In this post, we will look at the use of a small JavaScript utility that allows us to structure our JavaScript programs in the form of “classes” and objects.

Java JList Example

via Java JList Example | Examples Java Code Geeks.

In this example we are going to demonstrate how to use Java Swing JList, JList is a Swing component with which we can display a list of elements. This component also allows the user to select one or more elements visually. This article shows how to work with JList features using a simple example where we build a GUI with a JList to show a list of employee names and let us add/remove a single name to/from the JList dynamically.

JFileChooser Swing Example

via JFileChooser Swing Example | Examples Java Code Geeks.

The JFileChooser Component is used to create a cross platform directory explorer that can be used for a Java Desktop Application. For this blog post, I’ll showcase the how to use the component and call it from a Java class.

Drawing Swing JTable rows with different colors using TableCellRenderer interface Example

via Drawing Swing JTable rows with different colors using TableCellRenderer interface Example | Examples Java Code Geeks.

In this example we are going to demonstrate how to use Java SwingTableCellRenderer interface to customize cell rendering. When a JTableobject is created, several default renderers are also created. Those renderers are capable of rendering Boolean choices, dates, image icons, numbers, and objects (as strings). If you do not explicitly attach a custom render to a column, a table component chooses a default renderer on your behalf. However, If you discover that a table component’s default renderers do not meet your needs. At that time, you will want to develop a custom renderer via an implementation of TableCellRenderer. So, we will showTableCellRenderer implementation in a real business case.

Let’s suppose that we need to create an application which monitor the stock market shares prices, it shows which share goes down and up. So, we need to show these share attributes (Symbol, Company Name,Price, Change, % Change, Volume). In addition, we also need to color each share price Change and % Change in Green when it goes up and in Red when it goes down.

To accomplish that task, we should do two things. First, we create a class that implements the TableCellRenderer interface and overrides that interface’s getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) method to return a Component reference to an object that performs the actual rendering. Second, we create an object from your class and call JTable’s setDefaultRenderer(Class<?> columnClass, TableCellRenderer renderer) method to establish that object as a cell renderer.