TextView widget

If we press "enter", we have a new line.

If we press "enter" more times then there are lines in the default sized window, then a vertical scrollbar appears.

If we write a long sentence, the text will wrap breaking lines between words.

If we have a loooooooooooooooooooooooooooooooooooong word, a horizontal scrollbar will appear.

This is an example of Gtk.TextView

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* This is the application. */
public class MyApplication : Gtk.Application {
	/* Override the 'activate' signal of GLib.Application. */
	protected override void activate () {
		/* Create the window of this application. */
		new MyWindow (this).show_all ();
	}
}

/* This is the window. */
class MyWindow: Gtk.ApplicationWindow {
	internal MyWindow (MyApplication app) {
		Object (application: app, title: "TextView Example");
		this.set_default_size (220, 200);

		var buffer = new Gtk.TextBuffer (null); //stores text to be displayed
		var textview = new Gtk.TextView.with_buffer (buffer); //displays TextBuffer
		textview.set_wrap_mode (Gtk.WrapMode.WORD); //sets line wrapping

		var scrolled_window = new Gtk.ScrolledWindow (null, null);
		scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC,
		                            Gtk.PolicyType.AUTOMATIC);

		scrolled_window.add (textview);
		scrolled_window.set_border_width (5);

		this.add (scrolled_window);
	}
}
/* main creates and runs the application. */
public int main (string[] args) {
	return new MyApplication ().run (args);
}

In this sample we used the following: