Java Code Examples for javax.swing.JComponent#doLayout()
The following examples show how to use
javax.swing.JComponent#doLayout() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentMorpher2.java From netbeans with Apache License 2.0 | 6 votes |
private Image getComponentImage(JComponent component) { // Initial component sizing & layout component.setSize((getClientSize().width == 0) ? component.getPreferredSize() : getClientSize()); // try to fit the component to ComponentMorpher component.doLayout(); // layout component // Correct component sizing & layout component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height component.doLayout(); // layout component // One more iteration because of nested JTextAreas component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height component.doLayout(); // layout component // Paint component into BufferedImage BufferedImage componentImage = new BufferedImage(component.getSize().width, component.getSize().height, BufferedImage.TYPE_INT_RGB); component.printAll(componentImage.getGraphics()); return componentImage; }
Example 2
Source File: PluggableTreeTableView.java From visualvm with GNU General Public License v2.0 | 6 votes |
private static void checkVisibility(JComponent comp) { if (comp == null) return; comp.invalidate(); comp.revalidate(); comp.doLayout(); comp.repaint(); for (Component c : comp.getComponents()) if (c.isVisible()) { comp.setVisible(true); return; } comp.setVisible(false); }
Example 3
Source File: ComponentMorpher2.java From visualvm with GNU General Public License v2.0 | 6 votes |
private Image getComponentImage(JComponent component) { // Initial component sizing & layout component.setSize((getClientSize().width == 0) ? component.getPreferredSize() : getClientSize()); // try to fit the component to ComponentMorpher component.doLayout(); // layout component // Correct component sizing & layout component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height component.doLayout(); // layout component // One more iteration because of nested JTextAreas component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height component.doLayout(); // layout component // Paint component into BufferedImage BufferedImage componentImage = new BufferedImage(component.getSize().width, component.getSize().height, BufferedImage.TYPE_INT_RGB); component.printAll(componentImage.getGraphics()); return componentImage; }
Example 4
Source File: SimpleXYChartUtils.java From visualvm with GNU General Public License v2.0 | 5 votes |
public static void setZoomingEnabled(JComponent chartUI, boolean enabled) { SimpleXYChart chart = (SimpleXYChart)chartUI.getClientProperty("chart"); // NOI18N if (chart.isZoomingEnabled() == enabled) return; else chart.setZoomingEnabled(enabled); JPanel sidePanel = (JPanel)chartUI.getClientProperty("sidePanel"); // NOI18N JPanel scrollerPanel = (JPanel)chartUI.getClientProperty("scrollerPanel"); // NOI18N if (enabled) { TransparentToolBar toolbar = new TransparentToolBar(false); for (Action action : chart.getActions()) toolbar.addItem(action); sidePanel.add(toolbar); JScrollBar scroller = chart.getScroller(); scroller.setSize(scroller.getPreferredSize()); scrollerPanel.add(scroller); chart.putClientProperty("scroller", scroller); // NOI18N } else { sidePanel.removeAll(); scrollerPanel.removeAll(); chart.putClientProperty("scroller", null); // NOI18N } sidePanel.setVisible(enabled); chartUI.doLayout(); chartUI.repaint(); }
Example 5
Source File: SimpleXYChartUtils.java From visualvm with GNU General Public License v2.0 | 5 votes |
public static void setLegendVisible(JComponent chartUI, boolean visible) { JPanel legendPanel = (JPanel)chartUI.getClientProperty("legendPanel"); // NOI18N legendPanel.setVisible(visible); chartUI.doLayout(); chartUI.repaint(); }
Example 6
Source File: MockComponent.java From pumpernickel with MIT License | 5 votes |
/** * Creates a MockComponent that resembles the argument component. * <P> * Note this method will traverse c and its subcomponents and may * temporarily change properties of inner components: such as the focused * state, the visibility, etc. * <P> * The goal is of this component is not to mirror the exact state of a * component, but rather to provide a sample image of this component in its * plain, unmodified, unused state. * * @param c */ public MockComponent(JComponent c) { Dimension preferredSize = c.getPreferredSize(); Dimension currentSize = c.getSize(); Dimension d = new Dimension(Math.max(preferredSize.width, currentSize.width), Math.max(preferredSize.height, currentSize.height)); if (currentSize.width == 0 || currentSize.height == 0) { // if the component isn't visible yet c.setSize(d); c.doLayout(); } storeState(c); image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, d.width, d.height); g.setComposite(AlphaComposite.SrcOver); c.paint(g); g.dispose(); setPreferredSize(d); setMinimumSize(d); setMaximumSize(d); setOpaque(c.isOpaque()); setName(c.getName()); setToolTipText(c.getToolTipText()); restoreState(c); }
Example 7
Source File: TabLayoutManager.java From netbeans with Apache License 2.0 | 4 votes |
final void resizeContainer() { JComponent c = ( JComponent ) container.getParent(); c.invalidate(); c.revalidate(); c.doLayout(); }