[英]Components choice for chat gui
事实上,我只是开始积极练习摇摆,以便我的理论知识得心应手:)我已经为聊天GUI实现做了很多,但最后还是遇到了一些问题。 所以我决定从头开始重新设计聊天GUI,但我需要为它做出正确的组件选择。
首先,我必须说第一个实现中没有“输入”功能。
我目前的聊天实现包含以下组件:
我认为我卡住和聊天GUI的原因应该从头开始重新设计:
还有一些其他问题,但它们不是那么关键,不能影响“返工决定”。
如果您能够提示某些组件适合这种应用程序(如基于上述“原因”的聊天),我将非常感激。
你的设计很糟糕,你应该心疼。
尝试从连续显示的一堆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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.