0
나는 라인 (103)에 java.awt.IllegalComponentStateException
을 받고 있어요 즉java.awt.IllegalComponentStateException
guiFrame.setLocationByPlatform(true)
모든 아이디어에 관한 방법을 해결하기 위해? 인스턴스를 생성하는 동안 나는 SwingUtilities.invokeLater
메쏘드에 그것을 감싸고있다. 그러나 여전히 그것은 튀어 나와있다.
코드 아래에 붙여 : 이미 setVisible(true)
라고 한 후 setLocationByPlatform(true)
를 호출 할 때
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class CardLayoutExample {
JFrame guiFrame = new JFrame();
CardLayout cards = new CardLayout();
JPanel cardPanel = new JPanel();
JPanel firstPanel = new JPanel();
private JPanel tabsPanel = new JPanel();
static boolean isYoutube = false;
static boolean isGmail = false;
private ImageIcon animatedGif;
private static final String FIRST_PANEL = "First Panel";
/*
* public static void main(String[] args) {
*
* // EventQueue.invokeLater(new Runnable() {
*
* @Override public void run() {
*
* new CardLayoutExample(); } });
*
* }
*/
public CardLayoutExample() {
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
guiFrame.setTitle("Services");
guiFrame.setSize(400, 300);
guiFrame.setLocationRelativeTo(null);
guiFrame.setLayout(new BorderLayout());
guiFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
Border outline = BorderFactory.createLineBorder(Color.black);
tabsPanel.setBorder(outline);
tabsPanel.setLayout(cards);
JLabel services = new JLabel("Please choose from the services below :-");
JButton youtube = new JButton();
youtube.setName("youtube");
ImageIcon youtubeIcon = new ImageIcon("images/youtube_icon.jpg");
youtube.setIcon(youtubeIcon);
youtube.setBorder(outline);
youtube.setRolloverEnabled(true);
animatedGif = new ImageIcon("images/plnttm.gif");
youtube.setRolloverIcon(animatedGif);
youtube.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
isGmail = false;
isYoutube = true;
NativeInterface.open();
UIUtils.setPreferredLookAndFeel();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cardPanel.removeAll();
cardPanel.add(createContentYoutube(),
BorderLayout.NORTH);
guiFrame.setSize(800, 600);
guiFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
guiFrame.setLocationByPlatform(true);
guiFrame.setVisible(true);
}
});
}
});
JButton gmail = new JButton();
gmail.setName("gmail");
ImageIcon gmailIcon = new ImageIcon("images/Gmail_Icon.png");
gmail.setIcon(gmailIcon);
gmail.setBorder(outline);
gmail.setRolloverEnabled(true);
animatedGif = new ImageIcon("images/plnttm.gif");
gmail.setRolloverIcon(animatedGif);
gmail.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
isGmail = true;
isYoutube = false;
NativeInterface.open();
UIUtils.setPreferredLookAndFeel();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cardPanel.removeAll();
cardPanel.add(createContentGmail(), BorderLayout.NORTH);
guiFrame.setSize(800, 600);
guiFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
guiFrame.setLocationByPlatform(true);
guiFrame.setVisible(true);
}
});
}
});
Box box = Box.createVerticalBox();
box.add(services);
box.add(Box.createVerticalStrut(20));
box.add(youtube);
box.add(Box.createVerticalStrut(20));
box.add(gmail);
firstPanel.setBackground(Color.white);
firstPanel.setLayout(new FlowLayout());
firstPanel.add(box);
tabsPanel.add(firstPanel, FIRST_PANEL);
cardPanel.setLayout(cards);
cards.show(cardPanel, "Web Browser");
guiFrame.setVisible(true);
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
guiFrame.add(tabsPanel, BorderLayout.WEST);
guiFrame.add(cardPanel, BorderLayout.CENTER);
guiFrame.setVisible(true);
}
public static JComponent createContentYoutube() {
JPanel contentPane = new JPanel(new BorderLayout());
JPanel webBrowserPanel = new JPanel(new BorderLayout());
webBrowserPanel.setBorder(BorderFactory
.createTitledBorder("Web Browser"));
final JWebBrowser webBrowser = new JWebBrowser();
webBrowser.navigate("http://youtube.com");
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
webBrowser.setBarsVisible(false);
contentPane.add(webBrowserPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4));
contentPane.add(buttonPanel, BorderLayout.SOUTH);
return contentPane;
}
public static JComponent createContentGmail() {
JPanel contentPane = new JPanel(new BorderLayout());
JPanel webBrowserPanel = new JPanel(new BorderLayout());
webBrowserPanel.setBorder(BorderFactory
.createTitledBorder("Web Browser"));
final JWebBrowser webBrowser = new JWebBrowser();
webBrowser.navigate("http://gmail.com");
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
webBrowser.setBarsVisible(false);
contentPane.add(webBrowserPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4));
contentPane.add(buttonPanel, BorderLayout.SOUTH);
return contentPane;
}
}