Reputation: 3912
I wrote such code today:
import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import net.miginfocom.swing.MigLayout;
@SuppressWarnings("serial")
public class mainClass extends JApplet {
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
JPanel czat = new JPanel();
setLayout(new MigLayout());
JPanel panel3 = new JPanel();
panel3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Gry"));
add(panel3, "height 200:75%:10000, width 200:75%:10000");
JPanel panel1 = new JPanel();
panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Gracze"));
add(panel1, "height 200:75%:10000, width 50:25%:10000, wrap");
JPanel panel2 = new JPanel();
panel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Czat"));
add(czat, "height 50:25%:10000, width 100%, span");
setVisible(true); // important
} catch (Exception e) {
e.printStackTrace();
}
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}
Can anyone tell, why it works in Applet viewer, not in browser? Was working before i used MigLayout. The html code im using is:
<html>
<applet alt = "Aplikacja klienta" code = 'mainClass' archive = 'applet.jar', width=500, height=500 />
</html>
I were looking in various places, but i cant find solution for that.
Thanks in advance, Marcin
Upvotes: 1
Views: 2874
Reputation: 168815
Try this version of the HTML instead, making sure to swap 'n.n' with the version number of MigLayout being used.
<html>
<body>
<applet
alt="Aplikacja klienta"
code='mainClass'
archive='applet.jar, miglayout-n.n-swing.jar, miglayout-n.n.jar'
width=500
height=500 >
</applet>
</body>
</html>
Don't be afraid to check the HTML with a validation service. That HTML was invalid in so many ways that I lost count!
As another tip, ensure the Java Console is configured to open when an applet is loaded. This is vital for applet development. Configure it under the last tab of the Java Control Panel.
Upvotes: 2