尝试这个法典的例子:
import java.awt.*;
import javax.swing.*;
public class InsetTesting extends JFrame
{
private void createAndDisplayGUI()
{
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationByPlatform(true);
JPanel contentPane = new JPanel();
contentPane.setOpaque(true);
contentPane.setBorder(BorderFactory.createLineBorder(
Color.DARK_GRAY.darker(), 5, true));
contentPane.setBackground(Color.WHITE);
add(contentPane, BorderLayout.CENTER);
pack();
setVisible(true);
}
public Insets getInsets()
{
return (new Insets(30, 20, 10, 20));
}
public Dimension getPreferredSize()
{
return (new Dimension(200, 400));
}
public static void main(Stringu005Bu005D args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new InsetTesting().createAndDisplayGUI();
}
});
}
}
这里的产出如下: