Chat Control - relu91/nifty-gui GitHub Wiki

Table of Contents

Chat Control

Description

The Nifty Chat Control demonstrates how you can combine multiple controls to form a new one. The Chat Control was created by Nifty User ractoc and represents a typical chat window. There is a scrollable area for the chat history, an area for the chat members (called Players in the control) as well as a textfield and a button to send a message.

The Chat Control is supposed to be used with some form of network protocol to send the messages (this is not included).

A Eventbus event is being generated when the user has entered a new text line. A single chat line can contain an optional icon as well.




Java API

The Chat Java API is used to:

  • add/remove players and
  • add a new line to the chat area.
Chat

Standard Parameters

The following tables describe all of the parameters that you can apply to the control when they are being created.

Name Datatype Default Description
lines Integer 10 The maximum number of lines visible in the history area of the chat without the need to scroll. This parameter directly influences the height of the control.
sendLabel String "Send" The send button text.
chatLineIconWidth SizeValue 25px Every chat line consists of an icon and a text. The chatLineIconWidth parameter determines the width of the chat line icon.
chatLineIconHeight SizeValue 25px Every chat line consists of an icon and a text. The chatLineIconHeight parameter determines the width of the chat line icon.
chatLineHeight SizeValue 25px Every chat line consists of an icon and a text. The chatLineHeight parameter determines the height of a chat line.

EventBus Notification

The ChatTextSendEvent is published on the EventBus when the user has entered a new line of text.

ChatTextSendEvent

Java Builder Example

// create the chat control allocating room to display 14 lines and change the send button text to "Send Message"
control(new ChatBuilder("chatId", 14) {{
  sendLabel("Send Message");
}});

XML Example

// create a chat control
<control id="chatId" name="nifty-chat" width="100%" height="100%" lines="14" sendLabel="Send Message" />

Complete Examples

Complete examples can be found in the new nifty-default-controls-example (using JavaBuilder only).

Back to Nifty Standard Controls (Nifty 1.3)

⚠️ **GitHub.com Fallback** ⚠️