implemented EDT for MainFrame, making access from non-UI thread possible
This commit is contained in:
parent
a0d28ecaa9
commit
e96d3c681b
1 changed files with 41 additions and 5 deletions
|
|
@ -11,7 +11,25 @@ public class MainFrame {
|
||||||
private JList<String> categoryList;
|
private JList<String> categoryList;
|
||||||
private JList<String> channelList;
|
private JList<String> channelList;
|
||||||
|
|
||||||
public void create(short width, short height, boolean fullscreen) {
|
public void setCategories(String[] categories) {
|
||||||
|
if (categoryList == null) {
|
||||||
|
categoryList = new JList<>(categories);
|
||||||
|
categoryList.setFont(font);
|
||||||
|
} else {
|
||||||
|
categoryList.setListData(categories);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChannels(String[] channels) {
|
||||||
|
if (channelList == null) {
|
||||||
|
channelList = new JList<>(channels);
|
||||||
|
channelList.setFont(font);
|
||||||
|
} else {
|
||||||
|
channelList.setListData(channels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void spawn(short width, short height, boolean fullscreen) {
|
||||||
font = new Font("Arial", Font.PLAIN, 48);
|
font = new Font("Arial", Font.PLAIN, 48);
|
||||||
|
|
||||||
frame = new JFrame(I18n.get("MainFrame_Title"));
|
frame = new JFrame(I18n.get("MainFrame_Title"));
|
||||||
|
|
@ -33,8 +51,7 @@ public class MainFrame {
|
||||||
items[i] = "item" + i;
|
items[i] = "item" + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryList = new JList<String>(items);
|
setCategories(items);
|
||||||
categoryList.setFont(font);
|
|
||||||
|
|
||||||
final JScrollPane categoryListScroll = new JScrollPane(categoryList);
|
final JScrollPane categoryListScroll = new JScrollPane(categoryList);
|
||||||
categoryListScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
|
categoryListScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
|
||||||
|
|
@ -43,8 +60,7 @@ public class MainFrame {
|
||||||
|
|
||||||
statusPanel.add(new JButton("status"));
|
statusPanel.add(new JButton("status"));
|
||||||
|
|
||||||
channelList = new JList<String>(items);
|
setChannels(items);
|
||||||
channelList.setFont(font);
|
|
||||||
|
|
||||||
final JScrollPane channelListScroll = new JScrollPane(channelList);
|
final JScrollPane channelListScroll = new JScrollPane(channelList);
|
||||||
channelListScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
|
channelListScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
|
||||||
|
|
@ -63,4 +79,24 @@ public class MainFrame {
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void create(short width, short height, boolean fullscreen) {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
spawn(width, height, fullscreen);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TEST: multi thread access
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] newChannels = new String[] {"first", "second"};
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
setChannels(newChannels);
|
||||||
|
});
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue