java.awt.LayoutManager Java Examples

The following examples show how to use java.awt.LayoutManager. 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: NimbusLookAndFeel.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Package private method which returns either BorderLayout.NORTH,
 * BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending
 * on the location of the toolbar in its parent. The toolbar might be
 * in PAGE_START, PAGE_END, CENTER, or some other position, but will be
 * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar
 * actually IS, with CENTER being NORTH.
 *
 * This code is used to determine where the border line should be drawn
 * by the custom toolbar states, and also used by NimbusIcon to determine
 * whether the handle icon needs to be shifted to look correct.
 *
 * Toollbars are unfortunately odd in the way these things are handled,
 * and so this code exists to unify the logic related to toolbars so it can
 * be shared among the static files such as NimbusIcon and generated files
 * such as the ToolBar state classes.
 */
static Object resolveToolbarConstraint(JToolBar toolbar) {
    //NOTE: we don't worry about component orientation or PAGE_END etc
    //because the BasicToolBarUI always uses an absolute position of
    //NORTH/SOUTH/EAST/WEST.
    if (toolbar != null) {
        Container parent = toolbar.getParent();
        if (parent != null) {
            LayoutManager m = parent.getLayout();
            if (m instanceof BorderLayout) {
                BorderLayout b = (BorderLayout)m;
                Object con = b.getConstraints(toolbar);
                if (con == SOUTH || con == EAST || con == WEST) {
                    return con;
                }
                return NORTH;
            }
        }
    }
    return NORTH;
}
 
Example #2
Source File: TraceTablePanelSettingDialog.java    From pega-tracerviewer with Apache License 2.0 6 votes vote down vote up
private JPanel getMainJPanel() {

        JPanel mainJPanel = new JPanel();

        LayoutManager layout = new BoxLayout(mainJPanel, BoxLayout.Y_AXIS);
        mainJPanel.setLayout(layout);

        JPanel settingsJPanel = getSettingsJPanel();
        JPanel buttonsJPanel = getButtonsJPanel();

        mainJPanel.add(settingsJPanel);
        mainJPanel.add(Box.createRigidArea(new Dimension(4, 2)));
        mainJPanel.add(buttonsJPanel);
        mainJPanel.add(Box.createRigidArea(new Dimension(4, 4)));
        // mainJPanel.add(Box.createHorizontalGlue());

        return mainJPanel;
    }
 
Example #3
Source File: NimbusLookAndFeel.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Package private method which returns either BorderLayout.NORTH,
 * BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending
 * on the location of the toolbar in its parent. The toolbar might be
 * in PAGE_START, PAGE_END, CENTER, or some other position, but will be
 * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar
 * actually IS, with CENTER being NORTH.
 *
 * This code is used to determine where the border line should be drawn
 * by the custom toolbar states, and also used by NimbusIcon to determine
 * whether the handle icon needs to be shifted to look correct.
 *
 * Toollbars are unfortunately odd in the way these things are handled,
 * and so this code exists to unify the logic related to toolbars so it can
 * be shared among the static files such as NimbusIcon and generated files
 * such as the ToolBar state classes.
 */
static Object resolveToolbarConstraint(JToolBar toolbar) {
    //NOTE: we don't worry about component orientation or PAGE_END etc
    //because the BasicToolBarUI always uses an absolute position of
    //NORTH/SOUTH/EAST/WEST.
    if (toolbar != null) {
        Container parent = toolbar.getParent();
        if (parent != null) {
            LayoutManager m = parent.getLayout();
            if (m instanceof BorderLayout) {
                BorderLayout b = (BorderLayout)m;
                Object con = b.getConstraints(toolbar);
                if (con == SOUTH || con == EAST || con == WEST) {
                    return con;
                }
                return NORTH;
            }
        }
    }
    return NORTH;
}
 
Example #4
Source File: NimbusLookAndFeel.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Package private method which returns either BorderLayout.NORTH,
 * BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending
 * on the location of the toolbar in its parent. The toolbar might be
 * in PAGE_START, PAGE_END, CENTER, or some other position, but will be
 * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar
 * actually IS, with CENTER being NORTH.
 *
 * This code is used to determine where the border line should be drawn
 * by the custom toolbar states, and also used by NimbusIcon to determine
 * whether the handle icon needs to be shifted to look correct.
 *
 * Toollbars are unfortunately odd in the way these things are handled,
 * and so this code exists to unify the logic related to toolbars so it can
 * be shared among the static files such as NimbusIcon and generated files
 * such as the ToolBar state classes.
 */
static Object resolveToolbarConstraint(JToolBar toolbar) {
    //NOTE: we don't worry about component orientation or PAGE_END etc
    //because the BasicToolBarUI always uses an absolute position of
    //NORTH/SOUTH/EAST/WEST.
    if (toolbar != null) {
        Container parent = toolbar.getParent();
        if (parent != null) {
            LayoutManager m = parent.getLayout();
            if (m instanceof BorderLayout) {
                BorderLayout b = (BorderLayout)m;
                Object con = b.getConstraints(toolbar);
                if (con == SOUTH || con == EAST || con == WEST) {
                    return con;
                }
                return NORTH;
            }
        }
    }
    return NORTH;
}
 
Example #5
Source File: NimbusLookAndFeel.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Package private method which returns either BorderLayout.NORTH,
 * BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending
 * on the location of the toolbar in its parent. The toolbar might be
 * in PAGE_START, PAGE_END, CENTER, or some other position, but will be
 * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar
 * actually IS, with CENTER being NORTH.
 *
 * This code is used to determine where the border line should be drawn
 * by the custom toolbar states, and also used by NimbusIcon to determine
 * whether the handle icon needs to be shifted to look correct.
 *
 * Toollbars are unfortunately odd in the way these things are handled,
 * and so this code exists to unify the logic related to toolbars so it can
 * be shared among the static files such as NimbusIcon and generated files
 * such as the ToolBar state classes.
 */
static Object resolveToolbarConstraint(JToolBar toolbar) {
    //NOTE: we don't worry about component orientation or PAGE_END etc
    //because the BasicToolBarUI always uses an absolute position of
    //NORTH/SOUTH/EAST/WEST.
    if (toolbar != null) {
        Container parent = toolbar.getParent();
        if (parent != null) {
            LayoutManager m = parent.getLayout();
            if (m instanceof BorderLayout) {
                BorderLayout b = (BorderLayout)m;
                Object con = b.getConstraints(toolbar);
                if (con == SOUTH || con == EAST || con == WEST) {
                    return con;
                }
                return NORTH;
            }
        }
    }
    return NORTH;
}
 
Example #6
Source File: NimbusLookAndFeel.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Package private method which returns either BorderLayout.NORTH,
 * BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending
 * on the location of the toolbar in its parent. The toolbar might be
 * in PAGE_START, PAGE_END, CENTER, or some other position, but will be
 * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar
 * actually IS, with CENTER being NORTH.
 *
 * This code is used to determine where the border line should be drawn
 * by the custom toolbar states, and also used by NimbusIcon to determine
 * whether the handle icon needs to be shifted to look correct.
 *
 * Toollbars are unfortunately odd in the way these things are handled,
 * and so this code exists to unify the logic related to toolbars so it can
 * be shared among the static files such as NimbusIcon and generated files
 * such as the ToolBar state classes.
 */
static Object resolveToolbarConstraint(JToolBar toolbar) {
    //NOTE: we don't worry about component orientation or PAGE_END etc
    //because the BasicToolBarUI always uses an absolute position of
    //NORTH/SOUTH/EAST/WEST.
    if (toolbar != null) {
        Container parent = toolbar.getParent();
        if (parent != null) {
            LayoutManager m = parent.getLayout();
            if (m instanceof BorderLayout) {
                BorderLayout b = (BorderLayout)m;
                Object con = b.getConstraints(toolbar);
                if (con == SOUTH || con == EAST || con == WEST) {
                    return con;
                }
                return NORTH;
            }
        }
    }
    return NORTH;
}
 
Example #7
Source File: NimbusLookAndFeel.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Package private method which returns either BorderLayout.NORTH,
 * BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending
 * on the location of the toolbar in its parent. The toolbar might be
 * in PAGE_START, PAGE_END, CENTER, or some other position, but will be
 * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar
 * actually IS, with CENTER being NORTH.
 *
 * This code is used to determine where the border line should be drawn
 * by the custom toolbar states, and also used by NimbusIcon to determine
 * whether the handle icon needs to be shifted to look correct.
 *
 * Toollbars are unfortunately odd in the way these things are handled,
 * and so this code exists to unify the logic related to toolbars so it can
 * be shared among the static files such as NimbusIcon and generated files
 * such as the ToolBar state classes.
 */
static Object resolveToolbarConstraint(JToolBar toolbar) {
    //NOTE: we don't worry about component orientation or PAGE_END etc
    //because the BasicToolBarUI always uses an absolute position of
    //NORTH/SOUTH/EAST/WEST.
    if (toolbar != null) {
        Container parent = toolbar.getParent();
        if (parent != null) {
            LayoutManager m = parent.getLayout();
            if (m instanceof BorderLayout) {
                BorderLayout b = (BorderLayout)m;
                Object con = b.getConstraints(toolbar);
                if (con == SOUTH || con == EAST || con == WEST) {
                    return con;
                }
                return NORTH;
            }
        }
    }
    return NORTH;
}
 
Example #8
Source File: NimbusLookAndFeel.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Package private method which returns either BorderLayout.NORTH,
 * BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending
 * on the location of the toolbar in its parent. The toolbar might be
 * in PAGE_START, PAGE_END, CENTER, or some other position, but will be
 * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar
 * actually IS, with CENTER being NORTH.
 *
 * This code is used to determine where the border line should be drawn
 * by the custom toolbar states, and also used by NimbusIcon to determine
 * whether the handle icon needs to be shifted to look correct.
 *
 * Toollbars are unfortunately odd in the way these things are handled,
 * and so this code exists to unify the logic related to toolbars so it can
 * be shared among the static files such as NimbusIcon and generated files
 * such as the ToolBar state classes.
 */
static Object resolveToolbarConstraint(JToolBar toolbar) {
    //NOTE: we don't worry about component orientation or PAGE_END etc
    //because the BasicToolBarUI always uses an absolute position of
    //NORTH/SOUTH/EAST/WEST.
    if (toolbar != null) {
        Container parent = toolbar.getParent();
        if (parent != null) {
            LayoutManager m = parent.getLayout();
            if (m instanceof BorderLayout) {
                BorderLayout b = (BorderLayout)m;
                Object con = b.getConstraints(toolbar);
                if (con == SOUTH || con == EAST || con == WEST) {
                    return con;
                }
                return NORTH;
            }
        }
    }
    return NORTH;
}
 
Example #9
Source File: NimbusLookAndFeel.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Package private method which returns either BorderLayout.NORTH,
 * BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending
 * on the location of the toolbar in its parent. The toolbar might be
 * in PAGE_START, PAGE_END, CENTER, or some other position, but will be
 * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar
 * actually IS, with CENTER being NORTH.
 *
 * This code is used to determine where the border line should be drawn
 * by the custom toolbar states, and also used by NimbusIcon to determine
 * whether the handle icon needs to be shifted to look correct.
 *
 * Toollbars are unfortunately odd in the way these things are handled,
 * and so this code exists to unify the logic related to toolbars so it can
 * be shared among the static files such as NimbusIcon and generated files
 * such as the ToolBar state classes.
 */
static Object resolveToolbarConstraint(JToolBar toolbar) {
    //NOTE: we don't worry about component orientation or PAGE_END etc
    //because the BasicToolBarUI always uses an absolute position of
    //NORTH/SOUTH/EAST/WEST.
    if (toolbar != null) {
        Container parent = toolbar.getParent();
        if (parent != null) {
            LayoutManager m = parent.getLayout();
            if (m instanceof BorderLayout) {
                BorderLayout b = (BorderLayout)m;
                Object con = b.getConstraints(toolbar);
                if (con == SOUTH || con == EAST || con == WEST) {
                    return con;
                }
                return NORTH;
            }
        }
    }
    return NORTH;
}
 
Example #10
Source File: CheckBoxBasedAncillaryFilter.java    From ghidra with Apache License 2.0 5 votes vote down vote up
protected JComponent createComponent() {
	LayoutManager manager = createLayoutManager();
	JPanel panel = new JPanel();
	panel.setLayout(manager);
	panel.setBorder(BorderFactory.createTitledBorder(filterName));

	addCheckBoxes(panel);

	return createFilterPanel(panel);
}
 
Example #11
Source File: JToolBar.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void setLayout(LayoutManager mgr) {
    LayoutManager oldMgr = getLayout();
    if (oldMgr instanceof PropertyChangeListener) {
        removePropertyChangeListener((PropertyChangeListener)oldMgr);
    }
    super.setLayout(mgr);
}
 
Example #12
Source File: DockTab.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void setLayout(LayoutManager mgr) {
    if (mgr instanceof PrecisionLayout) {
        super.setLayout(mgr);
    } else {
        throw new IllegalArgumentException("Must use a PrecisionLayout.");
    }
}
 
Example #13
Source File: AbstractScriptPanel.java    From binnavi with Apache License 2.0 5 votes vote down vote up
public AbstractScriptPanel(final LayoutManager layout) {
  super(layout);

  languageBox = new LanguageBox(getManager());
  languageBox.addActionListener(new InternalLanguageBoxListener());

  m_inputPane.setEditable(true);
  m_inputPane.setBackground(new Color((float) .97, (float) .97, 1));
  m_inputPane.setFont(new Font(GuiHelper.getMonospaceFont(), 0, 13));

  m_OutputPane.setDocument(m_PythonStdoutDocument);

  m_OutputPane.setEditable(false);
  m_OutputPane.setBackground(new Color((float) .97, (float) .97, 1));
  final JScrollPane inputScrollPane = new JScrollPane(m_inputPane);

  final TitledBorder inputAreaBorder =
      new TitledBorder(new LineBorder(Color.LIGHT_GRAY, 1, true), "Command Line");
  inputScrollPane.setBorder(inputAreaBorder);
  inputScrollPane.setPreferredSize(new Dimension(600, 200));

  final JScrollPane m_OutputScrollPane = new JScrollPane(m_OutputPane);

  final TitledBorder outputAreaBorder =
      new TitledBorder(new LineBorder(Color.LIGHT_GRAY, 1, true), "Output");
  m_OutputScrollPane.setBorder(outputAreaBorder);
  m_OutputScrollPane.setPreferredSize(new Dimension(600, 200));

  add(languageBox, BorderLayout.NORTH);
  add(new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, inputScrollPane, m_OutputScrollPane));

}
 
Example #14
Source File: ScrollablePanel.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constuctor for specifying the LayoutManager of the panel.
 *
 * @param layout the LayountManger for the panel
 */
public ScrollablePanel(LayoutManager layout) {
  super(layout);

  IncrementInfo block = new IncrementInfo(IncrementType.PERCENT, 100);
  IncrementInfo unit = new IncrementInfo(IncrementType.PERCENT, 10);

  setScrollableBlockIncrement(HORIZONTAL, block);
  setScrollableBlockIncrement(VERTICAL, block);
  setScrollableUnitIncrement(HORIZONTAL, unit);
  setScrollableUnitIncrement(VERTICAL, unit);
}
 
Example #15
Source File: MotifPopupMenuUI.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
    LayoutManager layout = c.getLayout();
    Dimension d = layout.preferredLayoutSize(c);
    String title = ((JPopupMenu)c).getLabel();
    if (titleFont == null) {
        UIDefaults table = UIManager.getLookAndFeelDefaults();
        titleFont = table.getFont("PopupMenu.font");
    }
    FontMetrics fm = c.getFontMetrics(titleFont);
    int         stringWidth = 0;

    if (title!=null) {
        stringWidth += SwingUtilities2.stringWidth(c, fm, title);
    }

    if (d.width < stringWidth) {
        d.width = stringWidth + 8;
        Insets i = c.getInsets();
        if (i!=null) {
            d.width += i.left + i.right;
        }
        if (border != null) {
            i = border.getBorderInsets(c);
            d.width += i.left + i.right;
        }

        return d;
    }
    return null;
}
 
Example #16
Source File: JToolBar.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void setLayout(LayoutManager mgr) {
    LayoutManager oldMgr = getLayout();
    if (oldMgr instanceof PropertyChangeListener) {
        removePropertyChangeListener((PropertyChangeListener)oldMgr);
    }
    super.setLayout(mgr);
}
 
Example #17
Source File: MotifPopupMenuUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
    LayoutManager layout = c.getLayout();
    Dimension d = layout.preferredLayoutSize(c);
    String title = ((JPopupMenu)c).getLabel();
    if (titleFont == null) {
        UIDefaults table = UIManager.getLookAndFeelDefaults();
        titleFont = table.getFont("PopupMenu.font");
    }
    FontMetrics fm = c.getFontMetrics(titleFont);
    int         stringWidth = 0;

    if (title!=null) {
        stringWidth += SwingUtilities2.stringWidth(c, fm, title);
    }

    if (d.width < stringWidth) {
        d.width = stringWidth + 8;
        Insets i = c.getInsets();
        if (i!=null) {
            d.width += i.left + i.right;
        }
        if (border != null) {
            i = border.getBorderInsets(c);
            d.width += i.left + i.right;
        }

        return d;
    }
    return null;
}
 
Example #18
Source File: MotifPopupMenuUI.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
    LayoutManager layout = c.getLayout();
    Dimension d = layout.preferredLayoutSize(c);
    String title = ((JPopupMenu)c).getLabel();
    if (titleFont == null) {
        UIDefaults table = UIManager.getLookAndFeelDefaults();
        titleFont = table.getFont("PopupMenu.font");
    }
    FontMetrics fm = c.getFontMetrics(titleFont);
    int         stringWidth = 0;

    if (title!=null) {
        stringWidth += SwingUtilities2.stringWidth(c, fm, title);
    }

    if (d.width < stringWidth) {
        d.width = stringWidth + 8;
        Insets i = c.getInsets();
        if (i!=null) {
            d.width += i.left + i.right;
        }
        if (border != null) {
            i = border.getBorderInsets(c);
            d.width += i.left + i.right;
        }

        return d;
    }
    return null;
}
 
Example #19
Source File: MotifPopupMenuUI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
    LayoutManager layout = c.getLayout();
    Dimension d = layout.preferredLayoutSize(c);
    String title = ((JPopupMenu)c).getLabel();
    if (titleFont == null) {
        UIDefaults table = UIManager.getLookAndFeelDefaults();
        titleFont = table.getFont("PopupMenu.font");
    }
    FontMetrics fm = c.getFontMetrics(titleFont);
    int         stringWidth = 0;

    if (title!=null) {
        stringWidth += SwingUtilities2.stringWidth(c, fm, title);
    }

    if (d.width < stringWidth) {
        d.width = stringWidth + 8;
        Insets i = c.getInsets();
        if (i!=null) {
            d.width += i.left + i.right;
        }
        if (border != null) {
            i = border.getBorderInsets(c);
            d.width += i.left + i.right;
        }

        return d;
    }
    return null;
}
 
Example #20
Source File: JToolBar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void setLayout(LayoutManager mgr) {
    LayoutManager oldMgr = getLayout();
    if (oldMgr instanceof PropertyChangeListener) {
        removePropertyChangeListener((PropertyChangeListener)oldMgr);
    }
    super.setLayout(mgr);
}
 
Example #21
Source File: JToolBar.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public void setLayout(LayoutManager mgr) {
    LayoutManager oldMgr = getLayout();
    if (oldMgr instanceof PropertyChangeListener) {
        removePropertyChangeListener((PropertyChangeListener)oldMgr);
    }
    super.setLayout(mgr);
}
 
Example #22
Source File: MainFrame.java    From lizzie with GNU General Public License v3.0 5 votes vote down vote up
public String getToolBarPosition() {
  LayoutManager layout = getContentPane().getLayout();
  if (layout instanceof LizzieLayout) {
    Lizzie.config.toolbarPosition = (String) ((LizzieLayout) layout).getConstraints(toolBar);
  } else if (layout instanceof BorderLayout) {
    Lizzie.config.toolbarPosition = (String) ((BorderLayout) layout).getConstraints(toolBar);
  }
  return Lizzie.config.toolbarPosition;
}
 
Example #23
Source File: GridBagUtils.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds a component to a panel with a grid bag layout.
 *
 * @param panel the panel to which to add the component
 * @param comp  the component to be added
 * @param gbc   the grid bag constraints to be used, can be <code>null</code> if <code>code</code> is not
 *              <code>null</code>
 */
public static void addToPanel(JPanel panel, Component comp, GridBagConstraints gbc) {
    LayoutManager layoutManager = panel.getLayout();
    if (!(layoutManager instanceof GridBagLayout)) {
        throw new IllegalArgumentException("'panel' does not have a GridBagLayout manager");
    }
    GridBagLayout gbl = (GridBagLayout) layoutManager;
    gbl.setConstraints(comp, gbc);
    panel.add(comp);
}
 
Example #24
Source File: ReflectionPanel.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setLayout(LayoutManager mgr) {
    if (initialized) {
        contentPane.setLayout(mgr);
    } else {
        super.setLayout(mgr);
    }
}
 
Example #25
Source File: MotifPopupMenuUI.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
    LayoutManager layout = c.getLayout();
    Dimension d = layout.preferredLayoutSize(c);
    String title = ((JPopupMenu)c).getLabel();
    if (titleFont == null) {
        UIDefaults table = UIManager.getLookAndFeelDefaults();
        titleFont = table.getFont("PopupMenu.font");
    }
    FontMetrics fm = c.getFontMetrics(titleFont);
    int         stringWidth = 0;

    if (title!=null) {
        stringWidth += SwingUtilities2.stringWidth(c, fm, title);
    }

    if (d.width < stringWidth) {
        d.width = stringWidth + 8;
        Insets i = c.getInsets();
        if (i!=null) {
            d.width += i.left + i.right;
        }
        if (border != null) {
            i = border.getBorderInsets(c);
            d.width += i.left + i.right;
        }

        return d;
    }
    return null;
}
 
Example #26
Source File: MotifPopupMenuUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
    LayoutManager layout = c.getLayout();
    Dimension d = layout.preferredLayoutSize(c);
    String title = ((JPopupMenu)c).getLabel();
    if (titleFont == null) {
        UIDefaults table = UIManager.getLookAndFeelDefaults();
        titleFont = table.getFont("PopupMenu.font");
    }
    FontMetrics fm = c.getFontMetrics(titleFont);
    int         stringWidth = 0;

    if (title!=null) {
        stringWidth += SwingUtilities2.stringWidth(c, fm, title);
    }

    if (d.width < stringWidth) {
        d.width = stringWidth + 8;
        Insets i = c.getInsets();
        if (i!=null) {
            d.width += i.left + i.right;
        }
        if (border != null) {
            i = border.getBorderInsets(c);
            d.width += i.left + i.right;
        }

        return d;
    }
    return null;
}
 
Example #27
Source File: Controler.java    From brModelo with GNU General Public License v3.0 5 votes vote down vote up
public void PopuleBarra(JComponent obj) {
    ButtonGroup buttons = new ButtonGroup();
    Barra = obj;

    Acao ac = new Acao(editor, "?", "Controler.interface.BarraLateral.Nothing.img", "Controler.interface.BarraLateral.Nothing.Texto", null);
    JToggleButton btn = arrume(new JToggleButton(ac));
    buttons.add(btn);
    obj.add(btn);
    btn.setSelected(true);
    ac.IDX = -1;
    this.BtnNothing = btn;
    int i = 0;
    for (ConfigAcao ca : Lista) {
        if (ca.tipo == TipoConfigAcao.tpBotoes || ca.tipo == TipoConfigAcao.tpAny) {
            ac = new Acao(editor, ca.texto, ca.ico, ca.descricao, ca.command);
            ac.IDX = i++;
            btn = arrume(new JToggleButton(ac));
            buttons.add(btn);
            //obj.add(btn);
            listaBotoes.put(ca.command, btn);
        }
    }
    menuComandos c = menuComandos.cmdDel;
    String str = "Controler.comandos." + c.toString().substring(3).toLowerCase();
    ac = new Acao(editor, Editor.fromConfiguracao.getValor(str + ".descricao"), str + ".img", str + ".descricao", c.toString());
    ListaDeAcoesEditaveis.add(ac);
    ac.normal = false;
    JButton btn2 = new JButton(ac);
    btn2.setHideActionText(true);
    btn2.setFocusable(false);
    btn2.setPreferredSize(new Dimension(40, 40));
    obj.add(btn2);

    LayoutManager la = obj.getLayout();
    if (la instanceof GridLayout) {
        ((GridLayout) la).setRows(i + 2);
    }
}
 
Example #28
Source File: DropPanel.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a standard panel with a drop shadow.
 *
 * @param layout                  The layout to use.
 * @param title                   The title to use.
 * @param font                    The font to use for the title.
 * @param onlyReportPreferredSize Whether or not minimum and maximum size is reported as
 *                                preferred size or not.
 */
public DropPanel(LayoutManager layout, String title, Font font, boolean onlyReportPreferredSize) {
    super(layout);
    setOpaque(true);
    setBackground(Color.WHITE);
    mTitledBorder = new TitledBorder(font, title);
    setBorder(new CompoundBorder(mTitledBorder, new EmptyBorder(0, 2, 1, 2)));
    setAlignmentY(TOP_ALIGNMENT);
    mOnlyReportPreferredSize = onlyReportPreferredSize;
}
 
Example #29
Source File: RoundedPanel.java    From littleluck with Apache License 2.0 5 votes vote down vote up
public RoundedPanel(LayoutManager layout, int cornerRadius) {
    super(layout);
    this.cornerRadius = cornerRadius;
    this.roundBounds = new RoundRectangle2D.Float(0,0,0,0,
            cornerRadius, cornerRadius);
    this.contentAreaFilled = true;
    setOpaque(false);
}
 
Example #30
Source File: MotifPopupMenuUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
    LayoutManager layout = c.getLayout();
    Dimension d = layout.preferredLayoutSize(c);
    String title = ((JPopupMenu)c).getLabel();
    if (titleFont == null) {
        UIDefaults table = UIManager.getLookAndFeelDefaults();
        titleFont = table.getFont("PopupMenu.font");
    }
    FontMetrics fm = c.getFontMetrics(titleFont);
    int         stringWidth = 0;

    if (title!=null) {
        stringWidth += SwingUtilities2.stringWidth(c, fm, title);
    }

    if (d.width < stringWidth) {
        d.width = stringWidth + 8;
        Insets i = c.getInsets();
        if (i!=null) {
            d.width += i.left + i.right;
        }
        if (border != null) {
            i = border.getBorderInsets(c);
            d.width += i.left + i.right;
        }

        return d;
    }
    return null;
}