Skip to content

Repository files navigation

Build on DebianBuild on FedoraBuild on UbuntuBuild on WindowsJitPack

Java-GTK

GTK 4 bindings for Java. It uses Java Native Access (JNA) to access GTK libraries.

POC screenshot

Example

packageexamples;
importch.bailu.gtk.gio.ApplicationFlags;
importch.bailu.gtk.gtk.Application;
importch.bailu.gtk.gtk.ApplicationWindow;
importch.bailu.gtk.gtk.Button;
importch.bailu.gtk.type.Strs;
publicclassHelloWorld {
publicstaticvoidmain(String[] args) {
varapp = newApplication("com.example.hello",
ApplicationFlags.FLAGS_NONE);
app.onActivate(() -> {
// Create a new windowvarwindow = newApplicationWindow(app);
// Create a new buttonvarbutton = newButton();
// Set button labelbutton.setLabel("Hello, World!");
// When the button is clicked, close the windowbutton.onClicked(window::close);
window.setChild(button);
window.show();
});
// Start application main loopvarresult = app.run(args.length, newStrs(args));
// Terminate with exit codeSystem.exit(result);
}
}

Build and run

./gradlew generate or make gen
Compiles and runs the code generator. This will generate Java code from GIR files.

./gradlew build or make
Creates library, javadoc and run tests

  • Output: jar, javadoc.jar and sources.jar in libray/build/libs/

./gradlew run or make run
Run the default demo application. There are more demo applications in examples/src/main/java/examples including GeoClue2 and Adwaita samples.

make install
Compile Java library, generate JAR archive and copy JAR archive as artifact to local Maven repository (~/.m2/repository).

Integration

Library and Javadoc is available via JitPack.

// build.gradle.kts
plugins {
application
}
repositories {
maven { url = uri("https://jitpack.io") }
}
dependencies {
implementation("com.github.bailuk:java-gtk:0.6.1")
}
application {
mainClass.set("examples.HelloWorld")
}

Modules

  • generator/: Kotlin application that generates Java code from GIR files (xml parser -> model builder -> writer). GIR files are taken from Debian dev packages.
  • java-gtk/ : java-gtk library depends on generated Java code.
  • examples/ : Some examples to test the bindings. Mostly ported from https://gitlab.gnome.org/GNOME/gtk/-/tree/main/demos/gtk-demo.

License

About

GTK bindings for Java

Topics

Resources

Stars

144 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages