Skip to content

8.1. From Swing to GTK+ ​

Simple GUI App ​

Java

java
import javax.swing.*;

public class HelloWorldFrame extends JFrame {

    public HelloWorldFrame() {
        JLabel label = new JLabel("Hello World");
        add(label);
        setSize(100, 100);
    }

    public static void main(String args[]) {
        JFrame frame = new HelloWorldFrame();
        frame.setVisible(true);
    }
}

Vala

vala
using Gtk;

public class HelloWorldWindow : Window {

    public HelloWorldWindow () {
        var label = new Label ("Hello World");
        add (label);
        set_default_size (100, 100);
    }
}

void main (string[] args) {
    Gtk.init (ref args);

    var win = new HelloWorldWindow ();
    win.show_all ();

    Gtk.main ();
}

Must be compiled with --pkg gtk+-3.0.

Transition Table ​

Rough equivalents between common Swing types and GTK+ 3 widgets. See Valadoc for full APIs.

SwingGTK+
JButtonButton
JCheckBoxCheckButton
JColorChooserColorSelection
JComboBoxComboBox
JComponentWidget
JDialogDialog
JEditorPaneTextView
JFileChooserFileChooserDialog
JFrameWindow
JLabelLabel
JListTreeView with ListStore
JMenuMenu
JMenuBarMenuBar
JOptionPaneMessageDialog
JPanelContainer (depending on layout: Box, Table, Fixed, …)
JPasswordFieldEntry with visibility = false
JProgressBarProgressBar
JRadioButtonRadioButton
JScrollPaneScrolledWindow
JSeparatorSeparator
JSliderScale
JSpinnerSpinButton
JSplitPanePaned
JTabbedPaneNotebook
JTableTreeView with ListStore
JTextAreaTextView
JTextFieldEntry
JTextPaneTextView
JToolBarToolbar
JToolTipTooltip
JTreeTreeView with TreeStore
JViewportViewport