How to make a scrollable TextField?


I’ve been trying to make a scrollable non-editable TextField for a while but without any luck.
It’s meant to be used in an online game to display the chat messages. Now I’ve seen and tested solutions with GUILayout.BeginScrollView, but those only work combined with a GUI.Label.

I want my users to be able to copy and paste the chat though and that seems impossible with a label, so I’m trying to use a TextField. But the TextField simply doesn’t get displayed within the ScrollView.

Has anyone ever done anything like that and can tell me how he did it, or does anyone have a good idea?


In your sample you’re mixing GUILayout and GUI functions. That’s not generally a problem, but they can’t interact the way you want. A GUILayout ScrollView can only contain GUILayout objects.

You want something like:

      scrollPosition = GUILayout.BeginScrollView(scrollPosition);
        GUILayout.TextArea(chatOutputString, GUILayout.Width(chatWindow_Rect.width));

Your problem seems to be that you’re mixing and matching GUI and GUILayout calls. This is usually a bad idea.

Because you also want to have the Label effect, that can simply be achieved by using the Label style in the TextField. If you don’t see anything in your own code, that may also be because either cw_width or cw_height are 0 or otherwise too small.

    GUILayout.BeginArea (new Rect (50, 50, 200, 200));
	scrollPosition = GUILayout.BeginScrollView (scrollPosition, GUILayout.Width (50), GUILayout.Height (100));
		GUILayout.TextField ("chatOutputStringgggggggggggg", "Label");
	GUILayout.EndScrollView ();
	GUILayout.EndArea ();