In my java program I would like to add an animated logo in some of the user interfaces. I used this code but it does not work . I have added the jflashplayer jar also . sill it does not work. can some one suggest a solution ?
try {
FlashPanel fp = new FlashPanel(new File("C:\\Users\\ASHAN\\Desktop\\grandmsz.swf"));
jPanel1.add(fp);
fp.isOpaque();
fp.play();
} catch (JFlashLibraryLoadFailedException ex) {
Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
} catch (JFlashInvalidFlashException ex) {
Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
} catch (FileNotFoundException ex) {
Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
}
Related
Every time I run my Java SE(swing) program it runs with Nimbus Look and Feel, but my design is based on Windows Look and Feel, how can I make it so that my default program running has Windows look and feel and not Nimbus?
I have searched in few places, they are saying to change "Nimbus" to "Windows" which does not work for me.
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
Replace...
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
With something more like...
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
You can read How to Set the Look and Feel more details
I want to change the look of a Java application. I'm just using Netbeans and I don't like the look of metal in it, Instead I want to change it to the Windows look. Is there any way to do it?
I want to make it look like this.
But instead, when I run it, this is what the default look or theme of it is.
Is there any steps to change the default look of it?
Basically:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Will set the Look and feel to the one that your Operating System uses.
Take a look at this java tutorial which also lists the available themes and how to apply them.
Try this :
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Metal".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(YourJavaApplicationName.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(YourJavaApplicationName.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(YourJavaApplicationName.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(YourJavaApplicationName.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
My program starts with a class that calls out a JFrame. On the frame, I have the LaF set up correctly, but when the main class calls it, the LaF doesn't take.
If I start only the file, it works. If I start the project, it doesn't.
The code below is under the main method on the frame.
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TelaTur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TelaTur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TelaTur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TelaTur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
If the main class calls it:
TelaTur tela = new TelaTur();
tela.setVisible(true);
It doesn't take. Opening just the file (on Netbeans Shift + F6) takes the LaF.
I´m looking for the answer to:
How to set the look and feel from the main class?
This answer is based on what #GilianJoosen wrote on comments.
I created a method named setLookAndFeel() and called it before the initComponents() method on the constructor.
Thanks for the answers.
Recently I made a desktop application for login system, I always run the program if i changed any code to be sure if this code is working well or not, Anyways when I run the program it always appears as an advanced design, I don't know what you call it.Let the images explain.
Basic design
http://www5.0zz0.com/2013/04/10/14/418370274.jpg
Advanced design
http://www5.0zz0.com/2013/04/10/14/868362737.jpg
Your basic design is basically Metal Look And Field and Advanced Design is Nimbus Look And Field so use the following code before creating object of the JFrame class.
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
This code will change any look and field to Nimbus Look and Field
I am dealing with JaudioTagger API to manipulate MP3 files, I have to repeat the following exceptions over and over again... I was thinking of having a generic exception handler where I could forward each exception maybe with a flag number and the generic method would be deal with it by having different switch cases maybe ? Is it possible ? I would really appreciate if someone could give the method signature or a way to call it
} catch (CannotReadException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (ReadOnlyFileException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvalidAudioFrameException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (TagException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
}
Pre-JDK 7 all you can do is write a utility function and call it from each of the catch blocks:
private void handle(Exception ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
}
private void someOtherMethod() {
try {
// something that might throw
} catch (CannotReadException ex) {
handle(ex);
} catch (ReadOnlyFileException ex) {
handle(ex);
} catch (IOException ex) {
handle(ex);
} catch (InvalidAudioFrameException ex) {
handle(ex);
} catch (TagException ex) {
handle(ex);
}
}
Starting in JDK 7, you can use multi-catch:
private void someOtherMethod() {
try {
// something that might throw
} catch (CannotReadException | ReadOnlyFileException | IOException
| InvalidAudioFrameException | TagException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
See "Catching multiple exceptions".
This answer is obsolete starting with Java 7. Use multi-catch like John Watts shows in his answer.
I suggest using
try {
/* ... your code here ... */
} catch (Exception ex) {
handle(ex);
}
And handle it this way: (you have to replace the OtherException that you don't handle or remove the throws)
private static void handle(Exception ex) throws SomeOtherException {
if (ex instanceof CannotReadException || ex instanceof ReadOnlyFileException) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
} else if (ex instanceof SomeOtherException) {
throw (SomeOtherException) ex;
} else if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else {
throw new RuntimeException(ex);
}
}