Example usage for java.awt.event ComponentAdapter ComponentAdapter

List of usage examples for java.awt.event ComponentAdapter ComponentAdapter

Introduction

In this page you can find the example usage for java.awt.event ComponentAdapter ComponentAdapter.

Prototype

ComponentAdapter

Source Link

Usage

From source file:Main.java

public Main() {
    state = new State();
    addComponentListener(new ComponentAdapter() {
        @Override//w  w  w  .  j a v a 2 s. c  o  m
        public void componentResized(ComponentEvent e) {
            state.setSize(getSize(), true);
        }

        @Override
        public void componentMoved(ComponentEvent e) {
        }

        @Override
        public void componentShown(ComponentEvent e) {
        }

        @Override
        public void componentHidden(ComponentEvent e) {
        }
    });
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:Main.java

/**
 * Force divider location for a JSplitPan in percent.
 *
 * @param splitter//from ww w . j  ava 2 s.c  om
 * @param proportion
 * @return
 */
public static JSplitPane setDividerLocation(final JSplitPane splitter, final double proportion) {
    if (splitter.isShowing()) {
        if (splitter.getWidth() > 0 && splitter.getHeight() > 0) {
            splitter.setDividerLocation(proportion);
        } else {
            splitter.addComponentListener(new ComponentAdapter() {
                @Override
                public void componentResized(ComponentEvent ce) {
                    splitter.removeComponentListener(this);
                    setDividerLocation(splitter, proportion);
                }
            });
        }
    } else {
        splitter.addHierarchyListener(new HierarchyListener() {
            @Override
            public void hierarchyChanged(HierarchyEvent e) {
                if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && splitter.isShowing()) {
                    splitter.removeHierarchyListener(this);
                    setDividerLocation(splitter, proportion);
                }
            }
        });
    }
    return splitter;
}

From source file:Main.java

public Main() {
    setPreferredSize(new Dimension(300, 300));
    getContentPane().setLayout(new BorderLayout());

    flowPanel.add(new JLabel("One"));
    flowPanel.add(new JLabel("Two"));
    flowPanel.add(new JLabel("Three"));
    flowPanel.add(new JLabel("Four"));
    flowPanel.add(new JLabel("Five"));

    getContentPane().add(flowPanel, BorderLayout.NORTH);
    addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent e) {
            Main.this.getContentPane().remove(flowPanel);
            Main.this.getContentPane().add(flowPanel);
        }/* w  w w . j a va 2 s  .  c  o m*/
    });
}

From source file:lu.lippmann.cdb.dt.ui.DecisionTreeToGraphViewHelper.java

public static GraphView buildGraphView(final CGraph cgraph, final EventPublisher eventPublisher,
        final CommandDispatcher commandDispatcher) {
    final GraphViewImpl graphView = new GraphViewImpl(eventPublisher, commandDispatcher);
    graphView.init();//from ww w  .  j a  va 2 s .  co  m
    graphView.setViewMode(ViewMode.Edit);
    graphView.setCGraph(cgraph);

    //Tricky way to autofit ...
    graphView.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            if (graphView != null) {
                graphView.autoFit();
            }
        }
    });

    return graphView;
}

From source file:Test.java

License:asdf

public ApplicationWindow() {
    this.setSize(300, 300);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.add(new JButton("asdf"));
    final Polygon myShape = getPolygon();
    this.addComponentListener(new ComponentAdapter() {
        @Override/* ww  w.  java 2 s  .com*/
        public void componentResized(ComponentEvent e) {
            setShape(myShape);
            ((JFrame) e.getSource()).setForeground(Color.red);
            ((JFrame) e.getSource()).setBackground(Color.red);
        }
    });

    this.setUndecorated(true);
}

From source file:DialogDesktop.java

public DialogDesktop(String title) {
    super(title);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    final JDesktopPane desk = new JDesktopPane();
    setContentPane(desk);//from   ww w .j ava 2s .  c o  m

    // Create our "real" application container; use any layout manager we
    // want.
    final JPanel p = new JPanel(new GridBagLayout());

    // Listen for desktop resize events so we can resize p. This will ensure
    // that
    // our container always fills the entire desktop.
    desk.addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent ev) {
            Dimension deskSize = desk.getSize();
            p.setBounds(0, 0, deskSize.width, deskSize.height);
            p.validate();
        }
    });

    // Add our application panel to the desktop. Any layer below the
    // MODAL_LAYER
    // (where the dialogs will appear) is fine. We'll just use the default
    // in
    // this example.
    desk.add(p);

    // Fill out our app with a few buttons that create dialogs
    JButton input = new JButton("Input");
    JButton confirm = new JButton("Confirm");
    JButton message = new JButton("Message");
    p.add(input);
    p.add(confirm);
    p.add(message);

    input.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            JOptionPane.showInternalInputDialog(desk, "Enter Name");
        }
    });

    confirm.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            JOptionPane.showInternalConfirmDialog(desk, "Is this OK?");
        }
    });

    message.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            JOptionPane.showInternalMessageDialog(desk, "The End");
        }
    });
}

From source file:com.gs.obevo.util.inputreader.DialogInputReader.java

@Override
public String readLine(String promptMessage) {
    final JTextField juf = new JTextField();
    JOptionPane juop = new JOptionPane(juf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog userDialog = juop.createDialog(promptMessage);
    userDialog.addComponentListener(new ComponentAdapter() {
        @Override/*from w w w  .j a v  a  2s.c o  m*/
        public void componentShown(ComponentEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    juf.requestFocusInWindow();
                }
            });
        }
    });
    userDialog.setVisible(true);
    int uresult = (Integer) juop.getValue();
    userDialog.dispose();
    String userName = null;
    if (uresult == JOptionPane.OK_OPTION) {
        userName = new String(juf.getText());
    }

    if (StringUtils.isEmpty(userName)) {
        return null;
    } else {
        return userName;
    }
}

From source file:org.monkeys.gui.PopupWindow.java

public PopupWindow(final Frame parent, final Component base) {
    super(parent);

    if (null == base) {
        throw new NullArgumentException("component");
    }//ww  w .j  a  v  a 2 s. c om

    this.addWindowFocusListener(new WindowAdapter() {
        @Override
        public void windowLostFocus(WindowEvent e) {
            hidePopup();
        }
    });
    base.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            hidePopup();
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            hidePopup();
        }

        @Override
        public void componentHidden(ComponentEvent e) {
            hidePopup();
        }
    });
    base.addHierarchyListener(new HierarchyListener() {
        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            hidePopup();
        }
    });
}

From source file:jasmine.imaging.core.JasmineCorrelationGraph.java

public void init() {

    setTitle("Feature Correlation with Training Data");

    chart = new JLabel();
    add(chart);//w  ww  .  j  a v a2 s.c o m

    addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent e) {
            drawChart();
        }
    });

    setSize(750, 480);
    setVisible(true);

    drawChart();

}

From source file:Main.java

/**
 * Force divider location for a JSplitPan with int position.
 *
 * @param splitter/*w  ww  .j  a va2s  .c o  m*/
 * @param position
 * @return
 */
public static JSplitPane setDividerLocation(final JSplitPane splitter, final int position) {
    if (splitter.isShowing()) {
        if (splitter.getWidth() > 0 && splitter.getHeight() > 0) {
            splitter.setDividerLocation(position);
        } else {
            splitter.addComponentListener(new ComponentAdapter() {
                @Override
                public void componentResized(ComponentEvent ce) {
                    splitter.removeComponentListener(this);
                    setDividerLocation(splitter, position);
                }
            });
        }
    } else {
        splitter.addHierarchyListener(new HierarchyListener() {
            @Override
            public void hierarchyChanged(HierarchyEvent e) {
                if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && splitter.isShowing()) {
                    splitter.removeHierarchyListener(this);
                    setDividerLocation(splitter, position);
                }
            }
        });
    }
    return splitter;
}