簡體   English   中英

Java窗口事件-最大化。 如何進行硬編碼?

[英]Java Window Event - Maximize. How to hardcode?

我有一個JDesktopPane和一個JInternalFrame。 我希望JInternalFrame完成后自動最大化。 如何對“最大化窗口”事件進行硬編碼?

創建框架后,請使用JInternalFrame.setMaximum(true)

這是最大化框架的方法:

JInternalFrame frame = ...
frame..setMaximum(true); // Maximize this window to fill up the whole desktop area

JInternalFrame的 setMaximum(boolean b)方法設置為“ true”會使其最大化。

例如:

JInternalFrame.setMaximum(true)

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class JInternalFrameMaximumTest {
  public JComponent makeUI() {
    final JDesktopPane desktop = new JDesktopPane();
    Action a1 = new AbstractAction("JInternalFrame#setMaximum") {
      @Override public void actionPerformed(ActionEvent e) {
        JInternalFrame f = new JInternalFrame("#",true,true,true,true);
        desktop.add(f);
        f.setVisible(true);
        try {
          f.setMaximum(true);
        } catch(java.beans.PropertyVetoException ex) {
          ex.printStackTrace();
        }
      }
    };
    Action a2 = new AbstractAction("DesktopManager#maximizeFrame(f)") {
      @Override public void actionPerformed(ActionEvent e) {
        JInternalFrame f = new JInternalFrame("#",true,true,true,true);
        desktop.add(f);
        f.setVisible(true);
        desktop.getDesktopManager().maximizeFrame(f);
      }
    };
    JToolBar toolbar = new JToolBar("toolbar");
    toolbar.add(new JButton(a1));
    toolbar.add(new JButton(a2));

    JPanel p = new JPanel(new BorderLayout());
    p.add(desktop);
    p.add(toolbar, BorderLayout.NORTH);
    return p;
  }
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      @Override public void run() {
        createAndShowGUI();
      }
    });
  }
  public static void createAndShowGUI() {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(new JInternalFrameMaximumTest().makeUI());
    f.setSize(640, 240);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM