本文整理了Java中javax.swing.JComponent.getPreferredSize()
方法的一些代码示例,展示了JComponent.getPreferredSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComponent.getPreferredSize()
方法的具体详情如下:
包路径:javax.swing.JComponent
类名称:JComponent
方法名:getPreferredSize
暂无
代码示例来源:origin: stackoverflow.com
+ "The effect we want is a multi-line label.";
JFrame f = new JFrame("Label Render Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textLabel.setSize(textLabel.getPreferredSize());
Dimension d = textLabel.getPreferredSize();
BufferedImage bi = new BufferedImage(
d.width,
JLabel imageLabel = new JLabel(ii);
f.getContentPane().add(imageLabel);
f.pack();
f.setLocationByPlatform(true);
f.setVisible(true);
代码示例来源:origin: stackoverflow.com
add(p);
validate();
panel.add(output, BorderLayout.SOUTH);
Dimension d = tableScroll.getPreferredSize();
d = new Dimension(450,d.height);
tableScroll.setPreferredSize(d);
panel.add( tableScroll, BorderLayout.CENTER );
代码示例来源:origin: stackoverflow.com
return getPreferredSize().width < getParent().getWidth();
getContentPane().add( scrollPane );
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setSize(400, 300);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
table.setPreferredScrollableViewportSize(table.getPreferredSize());
p.add(scroll, BorderLayout.CENTER);
代码示例来源:origin: stackoverflow.com
final JFrame frame = new JFrame("Nested Layout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
plafComponents.add(plafChooser);
plafComponents.add(pack);
SwingUtilities.updateComponentTreeUI(frame);
if (pack.isSelected()) {
frame.pack();
frame.setMinimumSize(frame.getSize());
gui.add(plafComponents, BorderLayout.NORTH);
Dimension tablePreferred = tableScroll.getPreferredSize();
tableScroll.setPreferredSize(
new Dimension(tablePreferred.width, tablePreferred.height/3) );
frame.pack();
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
final JScrollPane scroll = new JScrollPane(panel);
scroll.setPreferredSize(new Dimension(80,100));
gui.add(scroll, BorderLayout.CENTER);
JButton addLabel = new JButton("Add Label");
gui.add(addLabel, BorderLayout.NORTH);
ActionListener listener = new ActionListener() {
int counter = 0;
public void actionPerformed(ActionEvent ae) {
panel.add(new JLabel("Label " + ++counter));
panel.revalidate();
int height = (int)panel.getPreferredSize().getHeight();
scroll.getVerticalScrollBar().setValue(height);
代码示例来源:origin: stackoverflow.com
table.setPreferredScrollableViewportSize(table.getPreferredSize());
getContentPane().add( scrollPane );
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
JScrollPane scroll = new JScrollPane(panel);
scroll.setPreferredSize(new Dimension(80,100));
gui.add(scroll, BorderLayout.CENTER);
JButton addLabel = new JButton("Add Label");
gui.add(addLabel, BorderLayout.NORTH);
ActionListener listener = new ActionListener() {
int counter = 0;
public void actionPerformed(ActionEvent ae) {
panel.add(new JLabel("Label " + ++counter));
panel.revalidate();
int height = (int)panel.getPreferredSize().getHeight();
Rectangle rect = new Rectangle(0,height,10,10);
panel.scrollRectToVisible(rect);
代码示例来源:origin: stackoverflow.com
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JScrollPane scrollPane = new JScrollPane(table);
getContentPane().add(scrollPane);
public void run() {
TableCheckBox frame = new TableCheckBox();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.pack();
frame.setLocation(150, 150);
frame.setVisible(true);
代码示例来源:origin: camunda/camunda-bpm-platform
tb.add(new JLabel(" Font: "));
tb.add(fontCombo);
tb.add(fontSizeCombo);
tb.addSeparator();
tb.addSeparator();
newButton.setAlignmentX(0.5f);
fontCombo.setMaximumSize(fontCombo.getPreferredSize());
fontSizeCombo.setMaximumSize(
fontSizeCombo.getPreferredSize());
代码示例来源:origin: stackoverflow.com
p.add(makeTitledPanel("Bad: JTableHeader#setPreferredSize(...)", new JScrollPane(table1)));
p.add(makeTitledPanel("Override getPreferredSize()", scroll));
panel.add(p);
panel.add(new JButton(new AbstractAction("addColumn") {
@Override public void actionPerformed(ActionEvent e) {
t.getColumnModel().addColumn(new TableColumn());
JTableHeader h = t.getTableHeader();
Dimension d = h.getPreferredSize();
System.out.println(d);
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.getContentPane().add(new TableHeaderHeightTest().makeUI());
f.setSize(320, 320);
f.setLocationRelativeTo(null);
f.setVisible(true);
代码示例来源:origin: stackoverflow.com
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Dimension d = table.getPreferredSize();
scrollPane.setPreferredSize(
new Dimension(d.width,table.getRowHeight()*rows));
navigation.add(previous);
navigation.add(next);
gui.add(scrollPane, BorderLayout.CENTER);
gui.add(navigation, BorderLayout.SOUTH);
代码示例来源:origin: stackoverflow.com
panel.add(new JLabel(name, JLabel.LEFT));
panel.add(jtf);
list.add(jtf);
Dimension d = sp.getPreferredSize();
d.setSize(d.width, d.height / 2);
sp.setPreferredSize(d);
internaFrame.add(sp);
internaFrame.pack();
internaFrame.setVisible(true);
desktopPane.add(internaFrame);
JFrame frmtest = new JFrame();
frmtest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmtest.add(desktopPane);
frmtest.pack();
frmtest.setVisible(true);
list.get(0).requestFocusInWindow();
代码示例来源:origin: stackoverflow.com
add(checkBox, BorderLayout.WEST);
add(renderer, BorderLayout.CENTER);
private JTree tree = new JTree();
int hotspot = new JCheckBox().getPreferredSize().width;
代码示例来源:origin: stackoverflow.com
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JPanel bottomPanel = CreateBottomPanel();
frame = new JFrame("Comp Table Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(CompTableScrollpane, BorderLayout.CENTER);
frame.add(bottomPanel, BorderLayout.SOUTH);
frame.setPreferredSize(new Dimension(800, 400));
frame.setLocation(150, 150);
frame.pack();
frame.setVisible(true);
CompModel.addRow();
JTable table = new JTable(CompModel);
table.setRowHeight(new CompCellPanel().getPreferredSize().height);
table.setTableHeader(null);
CompCellEditorRenderer compCellEditorRenderer = new CompCellEditorRenderer();
panel.add(addButton);
return panel;
代码示例来源:origin: datacleaner/DataCleaner
protected void initialize() {
updateWindowTitle();
setIconImage(getWindowIcon());
setResizable(isWindowResizable());
final JComponent content = getWindowContent();
getContentPane().removeAll();
getContentPane().add(content);
getContentPane().setPreferredSize(content.getPreferredSize());
pack();
if (!initialized) {
WidgetUtils.centerOnScreen(this);
}
if (_windowContext != null) {
_windowContext.onShow(this);
}
}
代码示例来源:origin: stackoverflow.com
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p.add(f);
frame.add(p);
frame.pack();
frame.setVisible(true);
lastFocusableIndex = 0;
sl.setFocused(false);
autoSuggestionPopUpWindow.setVisible(false);
setFocusToTextField();
autoSuggestionPopUpWindow.setVisible(false);
setFocusToTextField();
suggestionsPanel.add(suggestionLabel);
if (tW < label.getPreferredSize().width) {
tW = label.getPreferredSize().width;
tH += label.getPreferredSize().height;
代码示例来源:origin: stackoverflow.com
panel.add(spinner);
Dimension prefSize = field.getPreferredSize();
prefSize = new Dimension(200, prefSize.height);
field.setPreferredSize(prefSize);
JFrame frame = new JFrame("SpinnerBigTextField");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
this.add(createPane(3, "One ", Color.red));
this.add(createPane(3, "Two ", Color.green));
this.add(createPane(10, "Three ", Color.blue));
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane jsp = new JScrollPane(this,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
this.validate();
Dimension d = this.getPreferredSize();
d.height /= 2;
jsp.getViewport().setPreferredSize(d);
jsp.getVerticalScrollBar().setUnitIncrement(
this.getPreferredSize().height / fields.size());
f.add(jsp);
f.pack();
f.setVisible(true);
代码示例来源:origin: stackoverflow.com
table.setPreferredScrollableViewportSize(table.getPreferredSize());
getContentPane().add( new JScrollPane(table) );
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible( true );
内容来源于网络,如有侵权,请联系作者删除!