当前位置: 首页>>代码示例>>Java>>正文


Java JComponent.setPreferredSize方法代码示例

本文整理汇总了Java中javax.swing.JComponent.setPreferredSize方法的典型用法代码示例。如果您正苦于以下问题:Java JComponent.setPreferredSize方法的具体用法?Java JComponent.setPreferredSize怎么用?Java JComponent.setPreferredSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JComponent的用法示例。


在下文中一共展示了JComponent.setPreferredSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTemplateChooser

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
protected WizardDescriptor.Panel<WizardDescriptor> createTemplateChooser() {
    WizardDescriptor.Panel<WizardDescriptor> panel = new ProjectTemplatePanel();
    JComponent jc = (JComponent)panel.getComponent ();
    jc.setPreferredSize( new java.awt.Dimension (500, 340) );
    jc.setName (NbBundle.getBundle (NewProjectWizard.class).getString ("LBL_NewProjectWizard_Name")); // NOI18N
    jc.getAccessibleContext ().setAccessibleName (NbBundle.getBundle (NewProjectWizard.class).getString ("ACSN_NewProjectWizard")); // NOI18N
    jc.getAccessibleContext ().setAccessibleDescription (NbBundle.getBundle (NewProjectWizard.class).getString ("ACSD_NewProjectWizard")); // NOI18N
    jc.putClientProperty (WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, new Integer (0));
    jc.putClientProperty (WizardDescriptor.PROP_CONTENT_DATA, new String[] {
            NbBundle.getBundle (NewProjectWizard.class).getString ("LBL_NewProjectWizard_Name"), // NOI18N
            NbBundle.getBundle (NewProjectWizard.class).getString ("LBL_NewProjectWizard_Dots")}); // NOI18N
            
    return panel;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:NewProjectWizard.java

示例2: resetPreferredSize

import javax.swing.JComponent; //导入方法依赖的package包/类
final void resetPreferredSize() {
    JComponent comp = getContentComponent();
    if (comp == null){
        return;
    }
    comp.setPreferredSize(null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:CompletionLayoutPopup.java

示例3: show

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * Create and display the popup at the given bounds.
 *
 * @param popupBounds location and size of the popup.
 * @param displayAboveCaret whether the popup is displayed above the anchor
 *  bounds or below them (it does not be right above them).
 */
private void show(Rectangle popupBounds, boolean displayAboveCaret) {
    // Hide the original popup if exists
    if (popup != null) {
        popup.hide();
        popup = null;
    }
    
    // Explicitly set the preferred size
    Dimension origPrefSize = getPreferredSize();
    Dimension newPrefSize = popupBounds.getSize();
    JComponent contComp = getContentComponent();
    if (contComp == null){
        return;
    }
    contComp.setPreferredSize(newPrefSize);
    showRetainedPreferredSize = newPrefSize.equals(origPrefSize);
    
    PopupFactory factory = PopupFactory.getSharedInstance();
    // Lightweight completion popups don't work well on the Mac - trying
    // to click on its scrollbars etc. will cause the window to be hidden,
    // so force a heavyweight parent by passing in owner==null. (#96717)
    
    JTextComponent owner = layout.getEditorComponent();
    if(owner != null && owner.getClientProperty("ForceHeavyweightCompletionPopup") != null) {
        owner = null;
    }
    
    // #76648: Autocomplete box is too close to text
    if(displayAboveCaret && Utilities.isMac()) {
        popupBounds.y -= 10;
    }
    
    popup = factory.getPopup(owner, contComp, popupBounds.x, popupBounds.y);
    popup.show();

    this.popupBounds = popupBounds;
    this.displayAboveCaret = displayAboveCaret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:46,代码来源:CompletionLayoutPopup.java

示例4: init

import javax.swing.JComponent; //导入方法依赖的package包/类
private void init(Runnable run) {
    this.run = run;
    JComponent c = ProgressHandleFactory.createProgressComponent(progressHandle);
    c.setPreferredSize(new Dimension(3 * c.getPreferredSize().width, 3 * c.getPreferredSize().height));
    c.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
    getContentPane().add(c);
    progressHandle.start();
    getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(JavaHelp.class, "ACSD_Loading_Dialog"));  //NOI18N
    pack();
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension me = getSize();
    setLocation((screen.width - me.width) / 2, (screen.height - me.height) / 2);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:JavaHelp.java

示例5: show

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * Create and display the popup at the given bounds.
 *
 * @param popupBounds location and size of the popup.
 * @param displayAboveCaret whether the popup is displayed above the anchor
 *  bounds or below them (it does not be right above them).
 */
private void show(Rectangle popupBounds, boolean displayAboveCaret) {
    // Hide the original popup if exists
    if (popup != null) {
        popup.hide();
        popup = null;
    }

    // Explicitly set the preferred size
    Dimension origPrefSize = getPreferredSize();
    Dimension newPrefSize = popupBounds.getSize();
    JComponent contComp = getContentComponent();
    if (contComp == null){
        return;
    }
    contComp.setPreferredSize(newPrefSize);
    showRetainedPreferredSize = newPrefSize.equals(origPrefSize);

    PopupFactory factory = PopupFactory.getSharedInstance();
    // Lightweight completion popups don't work well on the Mac - trying
    // to click on its scrollbars etc. will cause the window to be hidden,
    // so force a heavyweight parent by passing in owner==null. (#96717)

    JTextComponent owner = getEditorComponent();
    if(owner != null && owner.getClientProperty("ForceHeavyweightCompletionPopup") != null) { //NOI18N
        owner = null;
    }

    // #76648: Autocomplete box is too close to text
    if(displayAboveCaret && Utilities.isMac()) {
        popupBounds.y -= 10;
    }

    popup = factory.getPopup(owner, contComp, popupBounds.x, popupBounds.y);
    popup.show();

    this.popupBounds = popupBounds;
    this.displayAboveCaret = displayAboveCaret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:46,代码来源:CompletionLayoutPopup.java

示例6: popupMenuWillBecomeVisible

import javax.swing.JComponent; //导入方法依赖的package包/类
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
//		GMA 1.4.8: Now check which combo box event is coming from
		if ( e.getSource() == box ) {

//			***** Changed by A.K.M. 6/23/06 *****
//			setPrototypeDisplayValue restricts the size of the box to a fixed 
//			length of eight characters
			box.setPrototypeDisplayValue("WWWWWWWW");
//			The popup listener adjusts the size of the popup to match the size 
//			of the text being displayed
			JComboBox tempBox = (JComboBox) e.getSource();
			Object comp = tempBox.getUI().getAccessibleChild(tempBox, 0);
			if (!(comp instanceof JPopupMenu)) {
				return;
			}
			JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
			Dimension size = scrollPane.getPreferredSize();
			UnknownDataSet tester1 = (UnknownDataSet)tempBox.getSelectedItem();
			CustomBRGTable.setReverseYAxis(false);
			CustomBRGTable.setIgnoreZeros(false);
//			6.5 is a hardcoded value that approximates the size of a 
//			character in pixels
//			TODO: Find exact size of text in pixels and adjust 
//			size.width accordingly
			if (tester1 != null) {
				if (maxDBNameLength < tester1.desc.name.length())	{
						maxDBNameLength = tester1.desc.name.length();
				}
				size.width = (int)(maxDBNameLength * 6.5);
				scrollPane.setPreferredSize(size);
			}
//			***** Changed by A.K.M. 6/23/06 *****
		}
	}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:35,代码来源:CustomDB.java

示例7: decorateJComponent

import javax.swing.JComponent; //导入方法依赖的package包/类
private void decorateJComponent(JComponent component) {
    String prop = (String)component.getClientProperty("com.rapidminer.ui.label.type");
    if("header".equals(prop)) {
        component.setFont(OPEN_SANS_LIGHT_28);
        component.setForeground(SwingTools.RAPIDMINER_ORANGE);
    } else if("bold".equals(prop)) {
        component.setFont(OPEN_SANS_SEMIBOLD_14);
        component.setForeground(Color.DARK_GRAY);
    } else if("normal".equals(prop)) {
        component.setFont(OPEN_SANS_LIGHT_14);
        component.setForeground(Color.DARK_GRAY);
    } else if("large".equals(prop)) {
        component.setFont(OPEN_SANS_SEMIBOLD_16);
        component.setForeground(Color.DARK_GRAY);
    }

    prop = (String)component.getClientProperty("com.rapidminer.ui.button.type");
    if("cfa".equals(prop)) {
        component.setFont(OPEN_SANS_SEMIBOLD_14);
        component.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
    } else if("normal".equals(prop)) {
        component.setFont(OPEN_SANS_LIGHT_14);
        component.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        component.setMinimumSize(new Dimension(175, component.getPreferredSize().height));
        component.setPreferredSize(new Dimension(175, component.getPreferredSize().height));
    }

    prop = (String)component.getClientProperty("com.rapidmniner.ui.link_button.id");
    if(prop != null && component instanceof LinkButton) {
        ((LinkButton)component).setText(this.generateHTML(prop));
    }

    Color foregroundColor = (Color)component.getClientProperty("com.rapidminer.ui.label.foreground");
    if(foregroundColor != null) {
        component.setForeground(foregroundColor);
    }

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:39,代码来源:OnboardingDialog.java

示例8: TabbedPaneDemo

import javax.swing.JComponent; //导入方法依赖的package包/类
public TabbedPaneDemo() {
    super(new GridLayout(1, 1));

    JTabbedPane tabbedPane = new JTabbedPane();
    ImageIcon icon = createImageIcon("images/middle.gif");

    JComponent panel1 = makeTextPanel("Panel #1");
    tabbedPane.addTab("Tab 1", icon, panel1, "Does nothing");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    JComponent panel2 = makeTextPanel("Panel #2");
    tabbedPane.addTab("Tab 2", icon, panel2, "Does twice as much nothing");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    JComponent panel3 = makeTextPanel("Panel #2");
    tabbedPane.addTab("Tab 3", icon, panel3, "Still does nothing");
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    JComponent panel4 = makeTextPanel("Panel #4 (has a preferred size of 410 x 50).");
    panel4.setPreferredSize(new Dimension(410, 50));
    tabbedPane.addTab("Tab 4", icon, panel4, "Does nothing at all");
    tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);

    // Add the tabbed pane to this panel.
    add(tabbedPane);

    // The following line enables to use scrolling tabs.
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:30,代码来源:TabbedPaneDemo.java

示例9: buildControlPanel

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public JPanel buildControlPanel() {
	final JPanel panel = new JPanel();
	panel.setLayout(new BorderLayout());
	final JComponent c = new CochleaTow4EarControlPanel(CochleaTow4Ear.this);
	c.setPreferredSize(new Dimension(1000, 800));
	panel.add(new JScrollPane(c), BorderLayout.CENTER);
	return panel;
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:10,代码来源:CochleaTow4Ear.java

示例10: buildControlPanel

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public JPanel buildControlPanel() {
	final JPanel panel = new JPanel();
	panel.setLayout(new BorderLayout());
	final JComponent c = new CochleaLPControlPanel(CochleaLP.this);
	c.setPreferredSize(new Dimension(1000, 800));
	panel.add(new JScrollPane(c), BorderLayout.CENTER);
	return panel;
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:10,代码来源:CochleaLP.java

示例11: buildControlPanel

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public JPanel buildControlPanel() {
	final JPanel panel = new JPanel();
	panel.setLayout(new BorderLayout());
	final JComponent c = new SampleProbControlPanel(SampleProb.this);
	c.setPreferredSize(new Dimension(1000, 800));
	panel.add(new JScrollPane(c), BorderLayout.CENTER);
	return panel;
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:10,代码来源:SampleProb.java

示例12: installUI

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public void installUI(JComponent c) {
	super.installUI(c);
	if ((scrollbar.getOrientation() == JScrollBar.HORIZONTAL)) {
		c.setPreferredSize(new Dimension(15, c.getPreferredSize().height));
	} else {
		c.setPreferredSize(new Dimension(c.getPreferredSize().width, 15));
	}
	// c.setMaximumSize(new Dimension(10, Integer.MAX_VALUE));
}
 
开发者ID:kmarius,项目名称:xdman,代码行数:11,代码来源:XDMScrollBarUI.java

示例13: selectPlatform

import javax.swing.JComponent; //导入方法依赖的package包/类
private void selectPlatform (Node pNode) {
    Component active = null;
    for (Component c : cards.getComponents()) {
        if (c.isVisible() &&
            (c == jPanel1 || c == messageArea)) {
                active = c;
                break;
        }
    }
    final Dimension lastSize = active == null ?
        null :
        active.getSize();
    this.clientArea.removeAll();
    this.messageArea.removeAll();
    this.removeButton.setEnabled (false);
    if (pNode == null) {
        ((CardLayout)cards.getLayout()).last(cards);
        return;
    }
    JComponent target = messageArea;
    JComponent owner = messageArea;
    JavaPlatform platform = pNode.getLookup().lookup(JavaPlatform.class);
    if (pNode != getExplorerManager().getRootContext()) {
        if (platform != null) {
            this.removeButton.setEnabled (canRemove(platform, pNode.getLookup().lookup(DataObject.class)));
            if (!platform.getInstallFolders().isEmpty()) {
                this.platformName.setText(pNode.getDisplayName());
                for (FileObject installFolder : platform.getInstallFolders()) {
                    File file = FileUtil.toFile(installFolder);
                    if (file != null) {
                        this.platformHome.setText (file.getAbsolutePath());
                    }
                }
                target = clientArea;
                owner = jPanel1;
            }
        }
        Component component = null;
        if (pNode.hasCustomizer()) {
            component = pNode.getCustomizer();
        }
        if (component == null) {
            final PropertySheet sp = new PropertySheet();
            sp.setNodes(new Node[] {pNode});
            component = sp;
        }
        addComponent(target, component);
    }
    if (lastSize != null) {
        final Dimension newSize = owner.getPreferredSize();
        final Dimension updatedSize = new Dimension(
            Math.max(lastSize.width, newSize.width),
            Math.max(lastSize.height, newSize.height));
        if (!newSize.equals(updatedSize)) {
            owner.setPreferredSize(updatedSize);
        }
    }
    target.revalidate();
    CardLayout cl = (CardLayout) cards.getLayout();
    if (target == clientArea) {
        cl.first (cards);
    }
    else {
        cl.last (cards);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:67,代码来源:PlatformsCustomizer.java

示例14: setSize

import javax.swing.JComponent; //导入方法依赖的package包/类
public static void setSize(JComponent component, Dimension dimension) {
    component.setMinimumSize(dimension);
    component.setPreferredSize(dimension);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:UI.java

示例15: implement

import javax.swing.JComponent; //导入方法依赖的package包/类
public ChangeInfo implement() throws Exception {
    EditList edits = fix.getEditList();

    Document oldDoc = info.getSnapshot().getSource().getDocument(true);
    //OffsetRange range = edits.getRange();
    OffsetRange range = new OffsetRange(0, oldDoc.getLength());
    String oldSource = oldDoc.getText(range.getStart(), range.getEnd());

    String mimeType = (String) oldDoc.getProperty("mimeType"); //NOI18N
    BaseDocument newDoc = new BaseDocument(false, mimeType);

    Language language = (Language) oldDoc.getProperty(Language.class);
    newDoc.putProperty(Language.class, language);
    newDoc.insertString(0, oldSource, null);
    edits.applyToDocument(newDoc);
    String newSource = newDoc.getText(0, newDoc.getLength());

    String oldTitle = NbBundle.getMessage(PreviewHintFix.class, "CurrentSource");
    String newTitle = NbBundle.getMessage(PreviewHintFix.class, "FixedSource");

    final DiffController diffView = DiffController.create(
            new DiffSource(oldSource, oldTitle),
            new DiffSource(newSource, newTitle));


    JComponent jc = diffView.getJComponent();

    jc.setPreferredSize(new Dimension(800, 600));

    // Warp view to a particular diff?
    // I can't just always jump to difference number 0, because when a hint
    // has changed only the whitespace (such as the fix which moves =begin entries to column 0)
    // there are no diffs, even though I want to jump to the relevant line.
    final int index = 0;
    final int firstLine = diffView.getDifferenceCount() == 0 ? NbDocument.findLineNumber((StyledDocument) oldDoc, edits.getRange().
            getStart()) : -1;
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            if (firstLine != -1) {
                diffView.setLocation(DiffController.DiffPane.Base,
                        DiffController.LocationType.LineNumber, firstLine);
            } else if (diffView.getDifferenceCount() > 0) {
                diffView.setLocation(DiffController.DiffPane.Base,
                        DiffController.LocationType.DifferenceIndex, index);
            }
        }
    });

    JButton apply = new JButton(NbBundle.getMessage(PreviewHintFix.class, "Apply"));
    JButton ok = new JButton(NbBundle.getMessage(PreviewHintFix.class, "Ok"));
    JButton cancel = new JButton(NbBundle.getMessage(PreviewHintFix.class, "Cancel"));
    String dialogTitle = NbBundle.getMessage(PreviewHintFix.class, "PreviewTitle",
            fix.getDescription());

    DialogDescriptor descriptor =
            new DialogDescriptor(jc, dialogTitle, true,
            new Object[]{apply, ok, cancel}, ok, DialogDescriptor.DEFAULT_ALIGN, null, null,
            true);
    Dialog dlg = null;

    try {
        dlg = DialogDisplayer.getDefault().createDialog(descriptor);
        dlg.setVisible(true);
        if (descriptor.getValue() == apply) {
            fix.implement();
        }
    } finally {
        if (dlg != null) {
            dlg.dispose();
        }
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:76,代码来源:PreviewHintFix.java


注:本文中的javax.swing.JComponent.setPreferredSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。