事实上,我只是开始积极练习摇摆,以便我的理论知识得心应手:)我已经为聊天GUI实现做了很多工作,但最后还是遇到了一些问题。所以我决定从头开始重新设计聊天GUI,但我需要为它做出正确的组件选择。
首先,我必须说第一个实现中没有“输入”功能。
我目前的聊天实现包含以下组件:
我认为自己陷入困境并且聊天GUI的原因应该从头开始重新设计:
还有其他一些问题,但它们并不那么重要,也无法影响“返工决定”。
如果您能够根据上述“原因”提示哪些组件适用于聊天等应用程序,我将不胜感激。
答案 0 :(得分:2)
你的设计很糟糕,你应该心疼。
尝试从连续显示的一堆JLabel中复制一些文本。
只需使用JTextPane或类似的东西!这个函数来自我的程序,在一个扩展JTextPane的类中,它最后添加了一些文本,具有一些特殊的风格。你可以修改它来做你需要的任何事情。
public void append(String append,Color fg,Color bg, boolean bold,boolean italic, boolean underline) {
try {
// Get the text pane's document
StyledDocument doc = (StyledDocument)this.getDocument();
// The color must first be wrapped in a style
Style style = doc.addStyle("StyleName", null);
StyleConstants.setForeground(style, fg);
StyleConstants.setBackground(style,bg);
StyleConstants.setBold(style,bold);
StyleConstants.setItalic(style,italic);
StyleConstants.setUnderline(style,underline);
// Insert the text at the end of the text
doc.insertString(doc.getLength(), append, style);
} catch (Exception e) {
e.printStackTrace();
}
this.setCaretPosition (this.getDocument().getLength()-1);
}