Java Code Examples for javax.swing.JComponent.setPreferredSize()

The following are Jave code examples for showing how to use setPreferredSize() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: NewProjectWizard.java   View Source Code Vote up 5 votes
@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;
}
 
Example 2
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 5 votes
final void resetPreferredSize() {
    JComponent comp = getContentComponent();
    if (comp == null){
        return;
    }
    comp.setPreferredSize(null);
}
 
Example 3
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 4
Project: incubator-netbeans   File: JavaHelp.java   View Source Code Vote up 5 votes
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);
}
 
Example 5
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 5 votes
final void resetPreferredSize() {
    JComponent comp = getContentComponent();
    if (comp == null){
        return;
    }
    comp.setPreferredSize(null);
}
 
Example 6
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 7
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 8
Project: geomapapp   File: CustomDB.java   View Source Code Vote up 5 votes
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 *****
		}
	}
 
Example 9
Project: rapidminer   File: OnboardingDialog.java   View Source Code Vote up 5 votes
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);
    }

}
 
Example 10
Project: marathonv5   File: TabbedPaneDemo.java   View Source Code Vote up 5 votes
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);
}
 
Example 11
Project: jaer   File: CochleaTow4Ear.java   View Source Code Vote up 5 votes
@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;
}
 
Example 12
Project: jaer   File: CochleaLP.java   View Source Code Vote up 5 votes
@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;
}
 
Example 13
Project: jaer   File: SampleProb.java   View Source Code Vote up 5 votes
@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;
}
 
Example 14
Project: xdman   File: XDMScrollBarUI.java   View Source Code Vote up 5 votes
@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));
}
 
Example 15
Project: incubator-netbeans   File: PlatformsCustomizer.java   View Source Code Vote up 4 votes
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);
    }
}
 
Example 16
Project: incubator-netbeans   File: UI.java   View Source Code Vote up 4 votes
public static void setSize(JComponent component, Dimension dimension) {
    component.setMinimumSize(dimension);
    component.setPreferredSize(dimension);
}
 
Example 17
Project: incubator-netbeans   File: PreviewHintFix.java   View Source Code Vote up 4 votes
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;
}
 
Example 18
Project: incubator-netbeans   File: CollapsiblePanel.java   View Source Code Vote up 4 votes
public FilesPanel(VCSCommitPanel master, Map<String, VCSCommitFilter> filters, int preferedHeight)  {
    super(master, master.getModifier().getMessage(VCSCommitPanelModifier.BundleMessage.FILE_PANEL_TITLE), DEFAULT_DISPLAY_FILES);
    this.filters = filters;
    
    master.getCommitTable().labelFor(filesLabel);
    
    JComponent table = master.getCommitTable().getComponent();
    
    Mnemonics.setLocalizedText(filesLabel, getMessage("CTL_CommitForm_FilesToCommit"));         // NOI18N
    filesLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, filesLabel.getMaximumSize().height));
    
    table.setPreferredSize(new Dimension(0, preferedHeight));
    
    ButtonGroup bg = new ButtonGroup();
    toolbar = new JToolBar();
    toolbar.setFloatable(false);
    
    for (VCSCommitFilter filter : filters.values()) {
        
        JToggleButton tgb = new JToggleButton();
        tgb.setIcon(filter.getIcon()); 
        tgb.setToolTipText(filter.getTooltip()); 
        tgb.setFocusable(false);
        tgb.setSelected(filter.isSelected());
        tgb.addActionListener(this);                
        tgb.putClientProperty(TOOLBAR_FILTER, filter);
        bg.add(tgb);
        toolbar.add(tgb);
        
    }
    toolbar.setAlignmentX(LEFT_ALIGNMENT);        
    
    sectionPanel.add(toolbar);
    sectionPanel.add(table);
    sectionPanel.add(VCSCommitPanel.makeVerticalStrut(filesLabel, table, RELATED, sectionPanel));
    sectionPanel.add(filesLabel);
    
    sectionPanel.setAlignmentX(LEFT_ALIGNMENT);
    filesLabel.setAlignmentX(LEFT_ALIGNMENT);
    table.setAlignmentX(LEFT_ALIGNMENT);
}
 
Example 19
Project: geomapapp   File: SurveyPlannerSelector.java   View Source Code Vote up 4 votes
/**
 * align the component to the left side of the panel
 * @param comp
 */
void alignComponent(JComponent comp) {
	comp.setAlignmentX(Component.LEFT_ALIGNMENT);
	comp.setPreferredSize(compDim);
	comp.setMaximumSize(compDim);
}
 
Example 20
Project: geomapapp   File: MGGSelector.java   View Source Code Vote up 4 votes
void alignComponent(JComponent comp) {
	comp.setAlignmentX(Component.LEFT_ALIGNMENT);
	comp.setPreferredSize(compDim);
	comp.setMaximumSize(compDim);
}