Reputation: 13
i'm trying to set a look and feel of my GUI. I already caught the UnsupportedLookAndFeelException, but when i compile i get an error that says UnsupportedLookAndFeelException must be caught or declared to be thrown. The error is at this line: Ne r = new Ne();
Here's the code:
public static void main(String[] args) {
try{
UIManager man = new UIManager();
man.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel") ;
}
catch(UnsupportedLookAndFeelException ex){}
catch(Exception ex){}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Ne r = new Ne();
r.setVisible(true);
}
});
}
Upvotes: 0
Views: 203
Reputation: 19344
I would suggest reading some more on the try catch statements:
http://docs.oracle.com/javase/tutorial/essential/exceptions/
All in all, it seems that not all your code that can throw the exception is surrounded by the try.catch block
If you have an error with Ne r = new Ne()... move it into the try catch statement.
public static void main(String[] args) {
try{
UIManager man = new UIManager();
man.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel") ;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Ne r = new Ne();
r.setVisible(true);
}
});
}
catch(UnsupportedLookAndFeelException ex){}
catch(Exception ex){}
}
If you use an IDE such as eclipse, it has some build in error fixing methods that will surround the code you need which is a good start to figuring out what needs to be set in a try catch block
Upvotes: 3
Reputation: 859
I can't see how your code would catch the UnsupportedLookAndFeelException thrown by new Ne(). Why not just put the try-catch at the right level? ie:
public void run()
{
try
{
Ne r = new Ne();
r.setVisible(true);
} catch (UnsupportedLookAndFeelException e)
{
// Put some code here to do the right thing.
}
}
Upvotes: 0