Reputation: 3946
I am attempting to learn how to use GTK. I am familiar with Java's JSwing, but having a difficult time controlling GTK widgets.
Below I create a window and add a table container (which I assume is like a LayoutManager). I also add a Text View (which is similar to a JTextArea) in the first cell.
When I start typing in the text view and when my text passes the edge, my window grows. How can I make the window stay the same size and have scrolling ability in the Text View?
#include "window.h"
void window_create(ChatWindow* window)
{
//Allocate the actual window. Our ChatWindow object has a pointer to a GTKWidget called window
window->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//Set the size of the window
gtk_window_set_default_size(GTK_WINDOW(window->window), 250, 180);
//Close the program when they click the x button
g_signal_connect(window->window,"delete-event", G_CALLBACK(gtk_main_quit), NULL);
//Show the window
gtk_widget_show(window->window);
gtk_window_set_title(GTK_WINDOW(window->window),"Chat Program");
//Setup the Window
window->chatHistory = gtk_text_view_new(); //Allocate the new TextView
window->layout = gtk_table_new(4,4,TRUE);
gtk_table_attach_defaults(GTK_TABLE(window->layout), window->chatHistory, 0, 1, 0, 1 );
gtk_container_add(GTK_CONTAINER(window->window), window->layout);
gtk_widget_show_all(window->window);
}
Upvotes: 1
Views: 651
Reputation: 57854
Put the GtkTextView
inside a GtkScrolledWindow
and it will gain scrolling capabilities. The scrolled window will also make it not grow in size.
Upvotes: 2