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


Java JComponent.getPreferredSize方法代码示例

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


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

示例1: ComponentIcon

import javax.swing.JComponent; //导入方法依赖的package包/类
/** Create an icon.
* @param comp a component, which must be unattached to a container
*             and should not be used for other purposes
*/
public ComponentIcon(JComponent comp) {
    if (comp.getParent() != null) {
        throw new IllegalArgumentException();
    }

    this.comp = comp;

    Dimension size = comp.getPreferredSize();

    // Careful! If you have e.g. a JLabel with empty text, width = 0 => exceptions.
    // Must make sure it is at least a reasonable size.
    comp.setSize(Math.max(size.width, 16), Math.max(size.height, 16));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:SystemAction.java

示例2: getPreferredSize

import javax.swing.JComponent; //导入方法依赖的package包/类
public Dimension getPreferredSize() {
    //Optimize it shows 16% of painting time is in this call.  In some
    //cases it will be called more than once, so cache the return value
    if (prefSize == null) {
        JComponent jc = getRenderer(this);
        prefSize = jc.getPreferredSize();
    }

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

示例3: getPreferredSize

import javax.swing.JComponent; //导入方法依赖的package包/类
final Dimension getPreferredSize() {
    JComponent comp = getContentComponent();

    if (comp == null)
        return new Dimension(0, 0);
    
    int screenWidth = Utilities.getUsableScreenBounds().width;
    
    Dimension maxSize = new Dimension((int) (screenWidth * MAX_COMPL_COVERAGE),
            comp.getMaximumSize().height); //set maximum part of screen covered
    setMaxSize(comp, maxSize);
    
    return comp.getPreferredSize();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:CompletionLayoutPopup.java

示例4: paint

import javax.swing.JComponent; //导入方法依赖的package包/类
public void paint(Graphics g) {
    g.setColor(getBackground());
    g.fillRect(location.x, location.y, size.width, size.height);
    
    JComponent component = mainRenderer.getComponent();
    int componentWidth = component.getPreferredSize().width;
    int componentX = size.width - componentWidth;
    
    mainRenderer.move(location.x + componentX, location.y);
    component.setSize(componentWidth, size.height);
    component.paint(g);
    
    int freeWidth = size.width - maxRendererWidth - renderersGap();
    if (freeWidth >= MIN_BAR_WIDTH) {
        barRenderer.setSize(Math.min(freeWidth, MAX_BAR_WIDTH), size.height);
        barRenderer.move(location.x, location.y);
        barRenderer.paint(g);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:HideableBarRenderer.java

示例5: preferredLayoutSize

import javax.swing.JComponent; //导入方法依赖的package包/类
public Dimension preferredLayoutSize(Container parent) {
    JComponent filter = filterPanel;
    if (filter != null && !filter.isVisible()) filter = null;
    
    JComponent search = searchPanel;
    if (search != null && !search.isVisible()) search = null;
    
    Dimension dim = new Dimension();
    
    if (filter != null && search != null) {
        Dimension dim1 = filter.getPreferredSize();
        Dimension dim2 = search.getPreferredSize();
        dim.width = dim1.width + dim2.width + 1;
        dim.height = Math.max(dim1.height, dim2.height);
    } else if (filter != null) {
        dim = filter.getPreferredSize();
    } else if (search != null) {
        dim = search.getPreferredSize();
    }
    
    if ((filter != null || search != null) && hasBottomFilterFindMargin())
        dim.height += 1;
    
    return dim;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:DataView.java

示例6: setup

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
protected void setup()
{
	final JComponent south = createSouth();
	final JComponent north = createNamePanel(new JPanel());
	final JSeparator separator1 = new JSeparator();
	final JSeparator separator2 = new JSeparator();

	final int height3 = north.getPreferredSize().height;
	final int height2 = separator1.getPreferredSize().height;
	final int height4 = south.getPreferredSize().height;

	final int[] rows = {height3, 5, height2, 5, height4, 5, height2};
	final int[] cols = {600};

	setLayout(new TableLayout(rows, cols));

	add(north, new Rectangle(0, 0, 1, 1));
	add(separator1, new Rectangle(0, 2, 1, 1));
	add(south, new Rectangle(0, 4, 1, 1));
	add(separator2, new Rectangle(0, 6, 1, 1));
}
 
开发者ID:equella,项目名称:Equella,代码行数:23,代码来源:DecisionEditor.java

示例7: setupGUI

import javax.swing.JComponent; //导入方法依赖的package包/类
private void setupGUI()
{
	JComponent whoCanPanel = createWhoCanPanel();
	JComponent modePanel = createModePanel();

	container = new JPanel(new GridLayout(1, 1));

	JSeparator separator = new JSeparator();

	final int height1 = whoCanPanel.getPreferredSize().height;
	final int height2 = modePanel.getMinimumSize().height;
	final int height3 = separator.getPreferredSize().height;
	final int[] rows = {height1, height2, height3, TableLayout.FILL,};
	final int[] cols = {TableLayout.DOUBLE_FILL, TableLayout.FILL,};

	setLayout(new TableLayout(rows, cols));
	add(whoCanPanel, new Rectangle(0, 0, 1, 1));
	add(modePanel, new Rectangle(0, 1, 2, 1));
	add(separator, new Rectangle(0, 2, 2, 1));
	add(container, new Rectangle(0, 3, 2, 1));
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:AccessEditor.java

示例8: setShowComponent

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * Shows or hides a button component of the header.
 */
private void setShowComponent(JComponent component, int layoutIndex, boolean visible)
{
	int width = 0;
	if( visible )
	{
		width = component.getPreferredSize().width;
	}
	headerLayout.setColumnSize(layoutIndex, width);
}
 
开发者ID:equella,项目名称:Equella,代码行数:13,代码来源:Editor.java

示例9: getGreatestPreferredSize

import javax.swing.JComponent; //导入方法依赖的package包/类
public static Dimension getGreatestPreferredSize(JComponent... components)
{
	Dimension d = new Dimension();
	for( JComponent comp : components )
	{
		Dimension compSize = comp.getPreferredSize();
		d.width = Math.max(d.width, compSize.width);
		d.height = Math.max(d.height, compSize.height);
	}
	return d;
}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:AppletGuiUtils.java

示例10: 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

示例11: setup

import javax.swing.JComponent; //导入方法依赖的package包/类
private void setup(ShuffleInterface<T> si, String labelText, boolean allowUpDown)
{
	enabled = true;

	text = new JLabel(labelText);
	si.setParent(this);
	entry = si;

	add = new JButton("Add");
	remove = new JButton("Remove");

	add.addActionListener(this);
	remove.addActionListener(this);

	if( allowUpDown )
	{
		up = new JButton(new ImageIcon(getClass().getResource(UP_ICON)));
		down = new JButton(new ImageIcon(getClass().getResource(DOWN_ICON)));

		up.setEnabled(false);
		down.setEnabled(false);

		up.addActionListener(this);
		down.addActionListener(this);
	}

	model = new GenericListModel<T>();
	list = new JList(model);
	list.addListSelectionListener(this);

	listScroll = new JScrollPane(list);
	JComponent entryComponent = entry.getComponent();

	int height1 = entryComponent.getPreferredSize().height;
	int height2 = add.getPreferredSize().height;
	int width1 = remove.getPreferredSize().width;
	int width2 = text.getPreferredSize().width - width1;
	if( width2 < 0 )
	{
		width2 = 0;
	}

	int[] rows = new int[]{height1, height2, height2, height2, height2, TableLayout.FILL};
	int[] columns = new int[]{width1, width2, TableLayout.FILL};
	TableLayout layout = new TableLayout(rows, columns, 5, 5);
	setLayout(layout);

	add(entryComponent, new Rectangle(0, 0, 3, 1));

	add(listScroll, new Rectangle(1, 1, 2, 5));

	add(add, new Rectangle(0, 1, 1, 1));
	add(remove, new Rectangle(0, 2, 1, 1));

	if( allowUpDown )
	{
		add(up, new Rectangle(0, 3, 1, 1));
		add(down, new Rectangle(0, 4, 1, 1));
	}

	refreshButtons();
}
 
开发者ID:equella,项目名称:Equella,代码行数:63,代码来源:JShuffleList.java

示例12: setButtonByCenterLeft

import javax.swing.JComponent; //导入方法依赖的package包/类
private void setButtonByCenterLeft(JComponent button, int x, int y)
{
	Dimension butsize = button.getPreferredSize();
	butsize.height = 20;
	button.setBounds(x+11, y-butsize.height+2, butsize.width, butsize.height);
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:7,代码来源:BracketPane.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;
    selectedPlatform = pNode.getLookup().lookup(AndroidSdk.class);
    if (pNode != getExplorerManager().getRootContext()) {
        if (selectedPlatform != null) {
            mkDefault.setEnabled(!selectedPlatform.isDefaultSdk());
            this.removeButton.setEnabled(!selectedPlatform.isDefaultSdk());
            if (!selectedPlatform.getInstallFolders().isEmpty()) {
                this.platformName.setText(pNode.getDisplayName());
                for (FileObject installFolder : selectedPlatform.getInstallFolders()) {
                    File file = FileUtil.toFile(installFolder);
                    if (file != null) {
                        this.platformHome.setText(file.getAbsolutePath());
                    }
                }
                target = clientArea;
                owner = jPanel1;
            }
        } else {
            removeButton.setEnabled(false);
            mkDefault.setEnabled(false);
        }
        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:NBANDROIDTEAM,项目名称:NBANDROID-V2,代码行数:70,代码来源:SdksCustomizer.java

示例14: setup

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public void setup(Set<String> grantedPrivileges, String name)
{
	getButtonActions(actions);

	listFilled = false;
	model = new GenericListModel<NameValue>();

	list = new JList<>(model);
	list.addMouseListener(new ListDoubleClickListener(list, editAction));
	list.addMouseListener(new ListPopupListener(list, actions));
	list.addListSelectionListener(new ListSelectionListener()
	{
		@Override
		public void valueChanged(ListSelectionEvent e)
		{
			updateButtons();
		}
	});

	JScrollPane scroll = new JScrollPane(list);

	JLabel heading = new JLabel(name);
	heading.setHorizontalAlignment(SwingConstants.CENTER);
	heading.setHorizontalTextPosition(SwingConstants.CENTER);

	JButton refreshButton = new JTextlessButton(refreshAction);
	refreshButton.setBorderPainted(false);
	refreshButton.setIconTextGap(0);
	refreshButton.setBorder(null);

	JComponent buttonsComp = createButtonsPanel();

	final int width1 = refreshButton.getPreferredSize().width;
	final int height1 = refreshButton.getPreferredSize().height;
	final int height2 = buttonsComp.getPreferredSize().height;

	final int[] rows = {5, height1, 5, TableLayout.FILL, 5, height2,};
	final int[] cols = {width1, TableLayout.FILL, width1, 5};

	everything = new JPanel(new TableLayout(rows, cols, 0, 0));
	everything.add(heading, new Rectangle(1, 1, 1, 1));
	everything.add(refreshButton, new Rectangle(2, 1, 1, 1));
	everything.add(scroll, new Rectangle(0, 3, 3, 1));
	everything.add(buttonsComp, new Rectangle(0, 5, 3, 1));

	updateButtons();
}
 
开发者ID:equella,项目名称:Equella,代码行数:49,代码来源:AdminToolList.java

示例15: setupGUI

import javax.swing.JComponent; //导入方法依赖的package包/类
private void setupGUI(RecipientFilter... filters)
{
	JLabel queryText = new JLabel(CurrentLocale.get("searching.userGroupRole.beforeQuery"));
	JLabel filterText = new JLabel(CurrentLocale.get("searching.userGroupRole.beforeFilters"));
	JLabel resultsText = new JLabel(CurrentLocale.get("searching.userGroupRole.results"));

	queryText.setHorizontalAlignment(SwingConstants.RIGHT);
	filterText.setHorizontalAlignment(SwingConstants.RIGHT);
	resultsText.setHorizontalAlignment(SwingConstants.RIGHT);

	JComponent filterPanel = createFilterPanel(filters);

	query = new JTextField();
	query.addActionListener(this);

	search = new JButton(CurrentLocale.get("searching.userGroupRole.executeQuery"));
	search.addActionListener(this);

	resultsModel = new GenericListModel<Object>();
	results = new JList(resultsModel);
	results.addListSelectionListener(this);
	setSingleSelectionOnly(false);

	JScrollPane resultsScroller = new JScrollPane(results);
	resultsScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

	final int height1 = query.getPreferredSize().height;
	final int height2 = filterPanel == null ? TableLayout.INVISIBLE : filterPanel.getPreferredSize().height;
	final int height3 = resultsText.getPreferredSize().height;
	final int width1 = queryText.getPreferredSize().width;
	final int width2 = search.getPreferredSize().width;

	final int[] rows = {height1, height2, height3, TableLayout.FILL,};
	final int[] cols = {width1, TableLayout.FILL, width2,};

	setLayout(new TableLayout(rows, cols));
	add(queryText, new Rectangle(0, 0, 1, 1));
	add(query, new Rectangle(1, 0, 1, 1));
	add(search, new Rectangle(2, 0, 1, 1));
	if( filterPanel != null )
	{
		add(filterText, new Rectangle(0, 1, 1, 1));
		add(filterPanel, new Rectangle(1, 1, 2, 1));
	}
	add(resultsText, new Rectangle(0, 2, 1, 1));
	add(resultsScroller, new Rectangle(1, 2, 2, 2));
}
 
开发者ID:equella,项目名称:Equella,代码行数:48,代码来源:SearchFinder.java


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