Java Utililty Methods Window

List of utility methods to do Window

Description

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

Method

voidmodifyDimensions(Window window)
modify Dimensions
if (window instanceof JFrame) {
    if (((JFrame) window).getExtendedState() == JFrame.MAXIMIZED_BOTH) {
        return;
Dimension result = window.getSize();
Dimension maxDimension = Toolkit.getDefaultToolkit().getScreenSize();
if (maxDimension.width < result.width) {
...
voidopenWindow(final JPanel panel)
Open a new window displaying a JPanel.
final javax.swing.JFrame jf = new javax.swing.JFrame(panel.getName());
jf.setSize(panel.getWidth(), panel.getHeight());
jf.add(panel, BorderLayout.CENTER);
jf.addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent e) {
        jf.dispose();
});
...
voidputWindowNormalBounds(Window window, Rectangle bounds)
Puts Window bounds to client property.
if (window instanceof JFrame) {
    ((JFrame) window).getRootPane().putClientProperty(WINDOW_STATE_NORMAL_BOUNDS, bounds);
voidremoveWindow(Window w)
Removes a window from the set (i.e.
synchronized (windows) {
    if (windows.remove(w)) {
        if (w instanceof Dialog && ((Dialog) w).isModal()) {
            modalDialogs.remove(w);
        fireWindowActionPerformed(new ActionEvent(w, Event.ACTION_EVENT, "remove")); 
voidrepaintMnemonicsInWindow(Window w)
repaint Mnemonics In Window
if (w == null || !w.isShowing()) {
    return;
Window[] ownedWindows = w.getOwnedWindows();
for (int i = 0; i < ownedWindows.length; i++) {
    repaintMnemonicsInWindow(ownedWindows[i]);
repaintMnemonicsInContainer(w);
...
voidsetWindowAlpha(Window w, int value)
set Window Alpha
if (w == null)
    return;
if (w.getPeer() == null) {
    w.pack();
java.awt.peer.ComponentPeer peer = w.getPeer();
try {
    invoke(peer, "setAlpha", (float) (value / 255f));
...
voidsetWindowOpacity(Window window, float opacity)
set Window Opacity
try {
    Class clazz = Class.forName("com.sun.awt.AWTUtilities");
    Method opacityMethod = clazz.getDeclaredMethod("setWindowOpacity", Window.class, float.class);
    opacityMethod.invoke(null, window, opacity);
} catch (Exception exc) {
    exc.printStackTrace();
voidshow(final Container container, final boolean visible, Window appearOnLeftSide)
show
if (visible)
    adjustLocation(container, appearOnLeftSide);
SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        container.setVisible(visible);
});
voidshow(JWindow window)
Shows a window.
window.setVisible(true);
voidshowLater(final Window win)
show Later
SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        win.setVisible(true);
});