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

The following are Jave code examples for showing how to use getPreferredSize() 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: SystemAction.java   View Source Code Vote up 6 votes
/** 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));
}
 
Example 2
Project: incubator-netbeans   File: RendererPropertyDisplayer.java   View Source Code Vote up 6 votes
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;
}
 
Example 3
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 6 votes
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();
}
 
Example 4
Project: incubator-netbeans   File: HideableBarRenderer.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 5
Project: incubator-netbeans   File: DataView.java   View Source Code Vote up 6 votes
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;
}
 
Example 6
Project: Equella   File: DecisionEditor.java   View Source Code Vote up 6 votes
@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));
}
 
Example 7
Project: Equella   File: AccessEditor.java   View Source Code Vote up 6 votes
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));
}
 
Example 8
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 5 votes
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();
}
 
Example 9
Project: Equella   File: Editor.java   View Source Code Vote up 5 votes
/**
 * 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);
}
 
Example 10
Project: Equella   File: AppletGuiUtils.java   View Source Code Vote up 5 votes
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;
}
 
Example 11
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 12
Project: Equella   File: JShuffleList.java   View Source Code Vote up 4 votes
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();
}
 
Example 13
Project: scorekeeperfrontend   File: BracketPane.java   View Source Code Vote up 4 votes
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);
}
 
Example 14
Project: NBANDROID-V2   File: SdksCustomizer.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;
    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);
    }
}
 
Example 15
Project: Equella   File: AdminToolList.java   View Source Code Vote up 4 votes
@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();
}
 
Example 16
Project: Equella   File: SearchFinder.java   View Source Code Vote up 4 votes
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));
}
 
Example 17
Project: Equella   File: ScriptPanel.java   View Source Code Vote up 4 votes
private JPanel createBasic()
{
	JLabel statementLabel = new JLabel(CurrentLocale.get("com.dytech.edge.admin.script.scriptpanel.statement")); //$NON-NLS-1$
	JLabel scriptLabel = new JLabel(CurrentLocale.get("com.dytech.edge.admin.script.scriptpanel.script")); //$NON-NLS-1$

	deleteButton = new JButton(CurrentLocale.get("com.dytech.edge.admin.script.scriptpanel.deleteline")); //$NON-NLS-1$
	importButton = new JButton(CurrentLocale.get("com.dytech.edge.admin.script.scriptpanel.importscript")); //$NON-NLS-1$
	exportButton = new JButton(CurrentLocale.get("com.dytech.edge.admin.script.scriptpanel.exportscript")); //$NON-NLS-1$

	importButton.addActionListener(this);
	deleteButton.addActionListener(this);
	exportButton.addActionListener(this);

	deleteButton.setEnabled(false);

	view = new ScriptView(model);
	view.addListSelectionListener(this);
	JScrollPane viewScroll = new JScrollPane(view);

	JComponent statement = model.getStatementEditor();

	final int height1 = statementLabel.getPreferredSize().height;
	final int height2 = statement.getPreferredSize().height;
	final int height3 = exportButton.getPreferredSize().height;
	final int width1 = Math.max(exportButton.getPreferredSize().width, importButton.getPreferredSize().width);

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

	JPanel all = new JPanel(new TableLayout(rows, cols, 5, 5));
	all.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

	all.add(statementLabel, new Rectangle(0, 0, 4, 1));
	all.add(statement, new Rectangle(0, 1, 4, 1));
	all.add(scriptLabel, new Rectangle(0, 2, 4, 1));
	all.add(viewScroll, new Rectangle(0, 3, 4, 1));
	all.add(deleteButton, new Rectangle(0, 4, 1, 1));
	all.add(importButton, new Rectangle(1, 4, 1, 1));
	all.add(exportButton, new Rectangle(2, 4, 1, 1));

	return all;
}
 
Example 18
Project: Equella   File: CalendarEditor.java   View Source Code Vote up 4 votes
private JComponent createDetails()
{
	JLabel titleLabel = new JLabel(CurrentLocale.get("wizard.controls.title"));
	JLabel descriptionLabel = new JLabel(CurrentLocale.get("wizard.controls.description"));

	title = new I18nTextField(BundleCache.getLanguages());
	description = new I18nTextField(BundleCache.getLanguages());

	JComponent dateSelection = generateDefaultDate();

	formatGroup = new ButtonGroup();

	JLabel formatLabel = new JLabel(getString("date.format"));
	dayMonthYear = new JRadioButton(getDateString("full"));
	formatGroup.add(dayMonthYear);
	monthYear = new JRadioButton(getDateString("month"));
	formatGroup.add(monthYear);
	year = new JRadioButton(getDateString("year"));
	formatGroup.add(year);
	dayMonthYear.setSelected(true);// default

	mandatory = new JCheckBox(CurrentLocale.get("wizard.controls.mandatory"));

	reload = new JCheckBox(CurrentLocale.get("wizard.controls.reload"));
	reload.addActionListener(new ReloadHandler(reload));

	final int width1 = formatLabel.getPreferredSize().width;
	final int height1 = title.getPreferredSize().height;
	final int height2 = dateSelection.getPreferredSize().height;
	final int height3 = dayMonthYear.getPreferredSize().height;

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

	JPanel all = new JPanel(new TableLayout(rows, cols, 5, 5));

	int row = -1;
	all.add(titleLabel, new Rectangle(0, ++row, 1, 1));
	all.add(title, new Rectangle(1, row, 1, 1));

	all.add(descriptionLabel, new Rectangle(0, ++row, 1, 1));
	all.add(description, new Rectangle(1, row, 1, 1));

	all.add(dateSelection, new Rectangle(0, ++row, 2, 1));
	// TODO: format so it doesn't look so ugly
	all.add(formatLabel, new Rectangle(0, ++row, 1, 1));
	all.add(dayMonthYear, new Rectangle(1, ++row, 1, 1));
	all.add(monthYear, new Rectangle(1, ++row, 1, 1));
	all.add(year, new Rectangle(1, ++row, 1, 1));

	all.add(mandatory, new Rectangle(0, ++row, 2, 1));

	all.add(reload, new Rectangle(0, ++row, 2, 1));

	if( getWizardType() != WizardHelper.WIZARD_TYPE_POWERSEARCH )
	{
		range = new JCheckBox(CurrentLocale.get("wizard.controls.timerange"));
		all.add(range, new Rectangle(0, ++row, 2, 1));
	}

	return all;
}
 
Example 19
Project: Equella   File: AbstractTreeWithView.java   View Source Code Vote up 4 votes
public void initialise(boolean allowReordering, int fixedEditorWidth)
{
	additionalActions = getAdditionalActions();
	if( additionalActions == null )
	{
		additionalActions = Collections.emptyList();
	}

	upDownActions = new ArrayList<TLEAction>();
	if( allowReordering )
	{
		upDownActions.add(upAction);
		upDownActions.add(downAction);
	}

	editorContainer = new JPanel(new GridLayout(1, 1));
	editorContainer.setBorder(AppletGuiUtils.DEFAULT_BORDER);
	editorContainer.add(getNoSelectionComponent());

	tree = new JTree(model.getUnderlyingTreeModel());
	tree.addMouseListener(new TreePopupListener(tree, new CombinedCollection<TLEAction>(additionalActions,
		upDownActions)));
	tree.addTreeSelectionListener(new TreeSelectionListener()
	{
		@Override
		public void valueChanged(TreeSelectionEvent e)
		{
			NODE_TYPE newSelection = getCurrentTreeSelection();
			if( !Objects.equals(currentSelection, newSelection) )
			{
				saveCurrentSelection();
				loadCurrentSelection();

				update();
			}
		}
	});

	JScrollPane treeScroller = new JScrollPane(tree);

	JComponent buttonsPanel = getButtonsPanel();

	JButton upButton = new JTextlessButton(upAction);
	JButton downButton = new JTextlessButton(downAction);

	final int height1 = upButton.getPreferredSize().height;
	final int height2 = buttonsPanel.getPreferredSize().height;
	final int width1 = upButton.getPreferredSize().width;
	final int width2 = fixedEditorWidth >= 0 ? TableLayout.FILL : buttonsPanel.getPreferredSize().width;
	final int width3 = fixedEditorWidth >= 0 ? fixedEditorWidth : TableLayout.FILL;

	final int[] rows = {TableLayout.FILL, height1, height1, TableLayout.FILL, height2,};
	final int[] cols = allowReordering ? new int[]{width1, width2, width3,} : new int[]{width2, width3,};

	setLayout(new TableLayout(rows, cols));

	int columnStart = 0;
	if( allowReordering )
	{
		columnStart = 1;
		add(upButton, new Rectangle(0, 1, 1, 1));
		add(downButton, new Rectangle(0, 2, 1, 1));
	}
	add(treeScroller, new Rectangle(columnStart, 0, 1, 4));
	add(buttonsPanel, new Rectangle(columnStart, 4, 1, 1));
	add(editorContainer, new Rectangle(columnStart + 1, 0, 1, 4));

	update();
}
 
Example 20
Project: Equella   File: JShuffleEditList.java   View Source Code Vote up 4 votes
private void setup(ShuffleInterface<T> si, String labelText, boolean allowUpDown)
{
	enabled = true;

	if( labelText == null )
	{
		labelText = DEFAULT_TEXT;
	}

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

	add = new JButton("Add");
	remove = new JButton("Remove");
	edit = new JButton("Update");
	edit.addActionListener(this);
	add.addActionListener(this);
	remove.addActionListener(this);
	edit.setEnabled(false);
	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, 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));
	add(edit, new Rectangle(0, 3, 1, 1));

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

	refreshButtons();
}