/** * Get the preferred size. It returns the actual size if there is one, the minimum size otherwise. */ public Dimension getPreferredSize() { java.awt.LayoutManager layout = getLayout(); if (layout != null) { return layout.preferredLayoutSize(this); } else { Dimension d = getSize(); if ((d.width == 0) || (d.height == 0)) { return getMinimumSize(); } else { return d; } } }
/** * Creation and initialization of a layout delegate for a new container. * * @param initialize * @return false if suitable layout delegate is not found * @throws java.lang.Exception * @throw IllegalArgumentException if the container instance is not empty */ public boolean prepareLayoutDelegate(boolean initialize) throws Exception { LayoutSupportDelegate delegate = null; LayoutManager lmInstance = null; // first try to find a dedicated layout delegate (for the container) Class<?> layoutDelegateClass = LayoutSupportRegistry.getSupportClassForContainer(radContainer.getBeanClass()); if (layoutDelegateClass != null) { delegate = (LayoutSupportDelegate) layoutDelegateClass.newInstance(); /* if (!delegate.checkEmptyContainer(getPrimaryContainer())) { RuntimeException ex = new IllegalArgumentException(); org.openide.ErrorManager.getDefault().annotate( ex, AbstractLayoutSupport.getBundle().getString( "MSG_ERR_NonEmptyContainer")); // NOI18N throw ex; } */ } else { Container contDel = getPrimaryContainerDelegate(); // if (contDel.getComponentCount() == 0) { // we can still handle only empty containers ... lmInstance = contDel.getLayout(); delegate = LayoutSupportRegistry.createSupportForLayout(lmInstance.getClass()); /* } else { RuntimeException ex = new IllegalArgumentException(); org.openide.ErrorManager.getDefault().annotate( ex, AbstractLayoutSupport.getBundle().getString( "MSG_ERR_NonEmptyContainer")); // NOI18N throw ex; } */ } if (delegate != null) { if (initialize) { setLayoutDelegate(delegate); } else { layoutDelegate = delegate; needInit = true; initializeFromInstance = lmInstance != null; } return true; } else { return false; } }
/** * If <code>c</code> is the <code>JOptionPane</code> the receiver is contained in, the preferred * size that is returned is the maximum of the preferred size of the <code>LayoutManager</code> * for the <code>JOptionPane</code>, and <code>getMinimumOptionPaneSize</code>. */ public Dimension getPreferredSize(JComponent c) { if (c == optionPane) { Dimension ourMin = getMinimumOptionPaneSize(); LayoutManager lm = c.getLayout(); if (lm != null) { Dimension lmSize = lm.preferredLayoutSize(c); if (ourMin != null) return new Dimension( Math.max(lmSize.width, ourMin.width), Math.max(lmSize.height, ourMin.height)); return lmSize; } return ourMin; } return null; }
/* * (non-Javadoc) * * @see javax.swing.JFrame#setLayout(java.awt.LayoutManager) */ @Override public void setLayout(LayoutManager manager) { if (manager.getClass() != RibbonFrameLayout.class) { LayoutManager currManager = getLayout(); if (currManager != null) { throw new IllegalArgumentException("Can't set a custom layout manager on JRibbonFrame"); } } super.setLayout(manager); }
public Test(LayoutManager layout, JComponent[] components) { super(layout.getClass().getName()); JPanel panel = new JPanel(layout); // --- code needed to add the components // less than using a GridBagLayout for (JComponent component : components) { panel.add(component); } // --- panel.setBorder(new EtchedBorder()); setContentPane(new JScrollPane(panel)); pack(); show(); }
/* * Test MetalInternalFrameTitlePane.MetalTitlePaneLayout class */ public void testMetalTitlePaneLayout() { TestMetalInternalFrameTitlePane pane = new TestMetalInternalFrameTitlePane(frame); pane.setSize(200, 31); LayoutManager layout = pane.getLayout(); final Rectangle iconButtonBounds = new Rectangle(134, 7, 16, 16); final Rectangle maximizeButtonBounds = new Rectangle(156, 7, 16, 16); final Rectangle closeButtonBounds = new Rectangle(178, 7, 16, 16); // test layoutContainer(): non-iconifiable, non-maximizable, non-closable layout.layoutContainer(null); // assertEquals("iconButton", zeroBounds, // pane.getComponent(0).getBounds()); // assertTrue("maximizeButton", pane.getComponent(1).getBounds(). // equals(zeroBounds)); // assertTrue("closeButton", pane.getComponent(2).getBounds(). // equals(zeroBounds)); // test layoutContainer(): iconifiable, maximizable, closable frame.setIconifiable(true); frame.setMaximizable(true); frame.setClosable(true); layout.layoutContainer(pane); if (isHarmony()) { assertEquals("iconButton", iconButtonBounds, pane.getComponent(0).getBounds()); assertEquals("maximizeButton", maximizeButtonBounds, pane.getComponent(1).getBounds()); assertEquals("closeButton", closeButtonBounds, pane.getComponent(2).getBounds()); } // test layoutContainer(): isPalette == true pane.setPalette(true); layout.layoutContainer(null); // these bounds can be changed in the future if (isHarmony()) { assertEquals( "palette: closeButton", new Rectangle(189, 11, 8, 8), pane.getComponent(0).getBounds()); } // minimumLayoutSize(), preferredLayoutSize() implementations assertTrue("", layout.minimumLayoutSize(pane) != null); assertTrue("", layout.preferredLayoutSize(pane) != null); }
public void testLayout() { CalculatorPanel c = new CalculatorPanel(); LayoutManager layout = c.getLayout(); assertEquals(FlowLayout.class, layout.getClass()); }