本文整理汇总了Java中java.awt.Container.setPreferredSize方法的典型用法代码示例。如果您正苦于以下问题:Java Container.setPreferredSize方法的具体用法?Java Container.setPreferredSize怎么用?Java Container.setPreferredSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Container
的用法示例。
在下文中一共展示了Container.setPreferredSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPreferredSize
import java.awt.Container; //导入方法依赖的package包/类
/** Resets the content pane's preferred size with a maximum width of 500. */
private void setPreferredSize() {
Container contentPane = getContentPane();
contentPane.setPreferredSize(null);
Dimension size = contentPane.getPreferredSize();
size.width = Math.min(size.width, 500);
contentPane.setPreferredSize(size);
}
示例2: loadInterface
import java.awt.Container; //导入方法依赖的package包/类
public static void loadInterface() {
frame = new JFrame(WINDOW_TITLE);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setFileFilter(new PtaFileFilter());
Container contentPane = frame.getContentPane();
SpringLayout layout = new SpringLayout();
contentPane.setLayout(layout);
contentPane.setPreferredSize(new Dimension(240, 200));
JPanel panel = new JPanel();
SpringLayout panelLayout = new SpringLayout();
panel.setLayout(panelLayout);
panel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
layout.putConstraint(SpringLayout.NORTH, panel, 5, SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.EAST, panel, -10, SpringLayout.EAST, contentPane);
layout.putConstraint(SpringLayout.SOUTH, panel, -30, SpringLayout.SOUTH, contentPane);
layout.putConstraint(SpringLayout.WEST, panel, 10, SpringLayout.WEST, contentPane);
contentPane.add(panel);
titleLabel = new JLabel("Directory Details");
titleLabel.setFont(new Font(titleLabel.getFont().getName(), Font.BOLD, 14));
panelLayout.putConstraint(SpringLayout.HORIZONTAL_CENTER, titleLabel, 0, SpringLayout.HORIZONTAL_CENTER, panel);
panelLayout.putConstraint(SpringLayout.NORTH, titleLabel, 5, SpringLayout.NORTH, panel);
panel.add(titleLabel);
JLabel filePathLabel = new JLabel("Path");
filePathLabel.setFont(new Font(filePathLabel.getFont().getName(), Font.BOLD, 13));
panelLayout.putConstraint(SpringLayout.NORTH, filePathLabel, 2, SpringLayout.SOUTH, titleLabel);
panelLayout.putConstraint(SpringLayout.WEST, filePathLabel, 10, SpringLayout.WEST, panel);
panel.add(filePathLabel);
pathLabel = new JLabel();
pathLabel.setFont(new Font(pathLabel.getFont().getName(), Font.PLAIN, 11));
panelLayout.putConstraint(SpringLayout.NORTH, pathLabel, 0, SpringLayout.SOUTH, filePathLabel);
panelLayout.putConstraint(SpringLayout.WEST, pathLabel, 10, SpringLayout.WEST, panel);
panelLayout.putConstraint(SpringLayout.EAST, pathLabel, 10, SpringLayout.EAST, panel);
panel.add(pathLabel);
actionButton = new JButton();
actionButton.setFocusable(false);
layout.putConstraint(SpringLayout.NORTH, actionButton, 5, SpringLayout.SOUTH, panel);
layout.putConstraint(SpringLayout.HORIZONTAL_CENTER, actionButton, 0, SpringLayout.HORIZONTAL_CENTER, contentPane);
layout.putConstraint(SpringLayout.SOUTH, actionButton, -5, SpringLayout.SOUTH, contentPane);
contentPane.add(actionButton);
panel.setVisible(true);
frame.pack();
promptForFile();
}