У меня есть два класса, один расширяющий другой.В обоих из них у меня есть поля, представляющие компоненты свинга.Проблема в том, что что-то не так, когда я пытаюсь использовать компоненты из дочернего класса - кажется, что поток Swing не имеет доступа к дочерним компонентам.Что я делаю не так?
public abstract class AppViewBase {
protected JPanel jContentPane = null;
protected void initialize() {
//...
addOutputControlls(jContentPane);
//...
}
protected abstract void addOutputControlls(JPanel jContentPane) ;
}
public class Titrai extends AppViewBase {
public JTextPane line1 = null;
public JTextPane line2 = null;
protected void addOutputControlls(JPanel jContentPane2) {
jContentPane2.add(getJTextPane());
jContentPane2.add(getJTextPane2());
}
public void setCurrentLine(Object selectedValue) {
String s = (String) selectedValue;
getJTextPane().setText(s);
getJTextPane2().setText("");
getJTextPane().repaint();
//only gets repainted i i move line1, line2 fields to parent class
getJTextPane2().repaint();
}
}
Редактировать - Код из комментария
if(EventQueue.isDispatchThread()) {
initialize();
} else {
try {
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
initialize();
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
Редактировать 2 - Код из OPДругой комментарий
JTextPane getJTextPane() {
if (line1 == null) {
line1 = new JTextPane();
line1.setFont(new Font("Tahoma", Font.PLAIN, 13));
line1.setForeground(Color.white);
line1.setPreferredSize(new Dimension(385, 16));
line1.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, false);
line1.setEditorKit(getDefaultLineEditorKit());
line1.setEditable(false);
line1.setLocation(new Point(15, 15));
line1.setSize(new Dimension(385, 16));
line1.setBackground(Color.black);
line1.setFocusable(false);
line1.setBorder(null);
}
return line1;
}