我尝试将滚动视图添加到JOptionsPane
,以便信息窗口可以处理更多文本。它会向窗口添加滚动窗格。但是,它在滚动时表现得很有趣。第一个可见文本清晰显示,但是当您开始滚动时,文本部分将相互重叠,直到文本区域全部为黑色。
您是否有解释这可能是什么,也许可以解决问题?
我的代码如下所示:
public void showInfoNoTranslation(String info) {
frame.requestFocusInWindow();
// create a JTextArea
JTextArea textArea = new JTextArea(info, 6, 25);
textArea.setEditable(false);
textArea.setBackground(new Color(255, 255, 255, 0));
textArea.setBorder(BorderFactory.createEmptyBorder());
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
// if (textArea.getLineCount() > 5) {
JScrollPane scrollPane = new JScrollPane(textArea);
JOptionPane.showMessageDialog(_frame, scrollPane, "title", JOptionPane.INFORMATION_MESSAGE);
}
答案 0 :(得分:2)
调用textArea.setOpaque(false);
而不是将其背景颜色设置为完全透明,它将起作用。
来自docs:
public void setOpaque(boolean isOpaque)
If true the component paints every pixel within its bounds. Otherwise, the component may not paint some or all of its pixels, allowing the underlying pixels to show through.
The default value of this property is false for JComponent. However, the default value for this property on most standard JComponent subclasses (such as JButton and JTree) is look-and-feel dependent.