hallo ich habe foldendes kleines Programm zum testen von Look and Feels
Nur leider ist das Anfangsfenster immer so klein, dass es beim Wechsel in andere Stile zu komischen Grafikfehlern kommt. Wenn man das Fenster größer zieht sieht es gut aus. Nur habe ich kein Einfluss auf die Größe. Ich habe es schon in der Main probiert mit frame.setSize(x,y) nun wie oben im Konstruktor mit this.setSize(x,y) aber die Größe bleibt gleich.
was läuft da falsch?
Gruß niesel
Java:
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Listing3501 extends JFrame implements ActionListener {
private static final String[] MONTH = {"Januar","Februar","Maerz",
"April", "Mai", "Juni", "Juli", "August", "September","Okober",
"November", "Dezember"
};
public Listing3501() {
super("Swing-Programm");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500, 800);
JPanel namePanel = new JPanel();
JLabel label = new JLabel("Name: ", new ImageIcon("triblue.gif"),SwingConstants.LEFT);
namePanel.add(label);
JTextField tf = new JTextField(30);
namePanel.add(tf);
....//ein paar Buttons usw
public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
try {
String plaf = "unknown";
if(cmd.equals("Metal")) {
plaf ="javax.swing.plaf.metal.MetalLookAndFeel";
}else if(cmd.equals("Motif")) {
plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
}else if(cmd.equals("Windows")) {
plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
}
UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
}catch(UnsupportedLookAndFeelException e) {
System.err.println(e.toString());
}catch(ClassNotFoundException e) {
System.err.println(e.toString());
}catch(InstantiationException e) {
System.err.println(e.toString());
}catch(IllegalAccessException e) {
System.err.println(e.toString());
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Listing3501 frame = new Listing3501();
//frame.setLocation(100,100);
//frame.setSize(800, 800);
frame.pack();
frame.setVisible(true);
}
}
was läuft da falsch?
Gruß niesel