Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
public class LayoutTest {
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(frame, BorderLayout.NORTH);
add(frame, BorderLayout.SOUTH);
add(frame, BorderLayout.WEST);
add(frame, BorderLayout.EAST);
add(frame, BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
private static void add(final JFrame frame, final String text) {
frame.add(label(text), text);
}
private static JLabel label(final String text) {
final JLabel label = new JLabel(text, SwingConstants.CENTER);
label.setBorder(BorderFactory.createLineBorder(Color.BLACK));
return label;
}
}
Die der Komponente, auf die du die Methoden aufrufst.getHeight/getWidth : Welche Höhe/Breite bekomme ich damit? Von dem Frame oder von was?
Nein, ich mache derzeit :Java:setLayout(null)
Ich ändere das mal auf BorderLayout... Mal sehen, ob es dann geht?