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.
| Swing | GTK+ |
|---|---|
JButton | Button |
JCheckBox | CheckButton |
JColorChooser | ColorSelection |
JComboBox | ComboBox |
JComponent | Widget |
JDialog | Dialog |
JEditorPane | TextView |
JFileChooser | FileChooserDialog |
JFrame | Window |
JLabel | Label |
JList | TreeView with ListStore |
JMenu | Menu |
JMenuBar | MenuBar |
JOptionPane | MessageDialog |
JPanel | Container (depending on layout: Box, Table, Fixed, …) |
JPasswordField | Entry with visibility = false |
JProgressBar | ProgressBar |
JRadioButton | RadioButton |
JScrollPane | ScrolledWindow |
JSeparator | Separator |
JSlider | Scale |
JSpinner | SpinButton |
JSplitPane | Paned |
JTabbedPane | Notebook |
JTable | TreeView with ListStore |
JTextArea | TextView |
JTextField | Entry |
JTextPane | TextView |
JToolBar | Toolbar |
JToolTip | Tooltip |
JTree | TreeView with TreeStore |
JViewport | Viewport |
