Java Utililty Methods JFrame

List of utility methods to do JFrame

Description

The list of methods to do JFrame are organized into topic(s).

Method

JFramegetParentJFrame(java.awt.Container component)
get Parent J Frame
while (component != null) {
    if (component.getClass().toString().equals("class javax.swing.JFrame")
            || component.getClass().getSuperclass().toString().equals("class javax.swing.JFrame")) {
        return (JFrame) component;
    component = component.getParent();
return null;
...
intgetPersistentExtendedStateMask(JFrame frame)
Gets JFrame extended state mask for this frame.
Object res = frame.getRootPane().getClientProperty(FRAME_PERSISTENT_EXTENDED_STATE_MASK);
if (res instanceof Integer) {
    return (Integer) res;
return Integer.MAX_VALUE;
javax.swing.JFramegetRootJFrame(Component c)
This is the only method that relies on Swing.
Object parent = c.getParent();
while (parent != null) {
    if (parent instanceof javax.swing.JFrame)
        return (javax.swing.JFrame) parent;
    parent = ((Component) parent).getParent();
return null;
ComponentgetRootJFrame(Component component)
Gets the root JFrame from the given Component Object.
while (null != component.getParent()) {
    component = component.getParent();
    if (component instanceof JFrame) {
        break;
return component;
JFramegetTheJFrame(String title, int width, int height, int x, int y)
get The J Frame
JFrame jframe = new JFrame(title);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setSize(width, height);
jframe.setLocation(x, y);
jframe.pack();
jframe.setVisible(true);
return jframe;
JFramegetTopJFrame(Container c)
get Top J Frame
if (c instanceof JFrame)
    return (JFrame) c;
Container theFrame = c;
do {
    theFrame = theFrame.getParent();
} while ((theFrame != null) && !(theFrame instanceof JFrame));
if (theFrame == null)
    theFrame = new JFrame();
...
StringgetUserInput(JFrame _frame, String arg1, String arg2, Object arg3)
get User Input
if (_frame == null)
    _frame = frame;
Object obj = JOptionPane.showInputDialog(_frame, arg1, arg2, JOptionPane.QUESTION_MESSAGE, null, null,
        arg3);
if (obj != null)
    return obj.toString();
return null;
JMenugetViewMenu(JFrame mainFrame)
get View Menu
JMenuBar menuBar = mainFrame.getJMenuBar();
MenuElement[] menuElements = menuBar.getSubElements();
for (MenuElement menuElement : menuElements) {
    if (menuElement instanceof JMenu) {
        JMenu menu = (JMenu) menuElement;
        String name = menu.getText();
        if (name.equalsIgnoreCase(MENU_NAME)) {
            return menu;
...
voidgiveFrameHalfScreen(final JFrame frame)
give Frame Half Screen
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
final Rectangle winSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
final int taskBarHeight = screenSize.height - winSize.height;
final int width = (int) (screenSize.width * 0.505);
final int height = screenSize.height - taskBarHeight;
frame.setSize(width, height);
voidigualarFormularios(JFrame destino, JFrame origen)
igualar Formularios
destino.setExtendedState(origen.getExtendedState());
if (origen.getExtendedState() == JFrame.NORMAL) {
    destino.setSize(origen.getSize());
    destino.setLocation(origen.getLocation());