2015-11-20 3 views
-1

Я попытался добавить прокрутку к JOptionsPane, так что информационное окно может обрабатывать больше текста. Он добавляет панель прокрутки в окно. Тем не менее, он действует смешно по прокрутке. Первый видимый текст отображается четко, но когда вы начинаете прокрутку, части текста будут перекрываться друг с другом, пока область текста не станет черной.JScrollPane действует смешно внутри 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

Параметр '_frame' является текущий кадр окно – Sulby

ответ

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. 
Смежные вопросы