JInternalFrameMinimize 时删除左上角下拉按钮

问题描述 投票:0回答:1

问题图片:

https://i.sstatic.net/7okl6JHe.png

没问题图片:

https://i.sstatic.net/9uzdGcKN.png

我正在使用 JInternalFrame 并删除框架左上角的下拉列表,因为它没有任何作用,我使用此代码(结果在图像中):

    public static void customizeInternalFrameUI(JInternalFrame internalFrame) {
        // Remove the top left button of the dropdown menu
        BasicInternalFrameUI ui = (BasicInternalFrameUI) internalFrame.getUI();
        Container north = (Container) ui.getNorthPane();
        north.remove(0);
        north.validate();
        north.repaint();
    }

当我再次展开窗口时,没有按钮(我在第一种情况下给出的代码始终有效)。

我想删除框架左上角的下拉列表,因为它不能最小化窗口(结果如图#2所示)。我怎么做这个?

我使用事件 formFrameIconified 和另一个事件。不是结果。

java swing user-interface netbeans jinternalframe
1个回答
0
投票

使用 JInternalFrame#setFrameIcon(Icon) 方法设置高度为零的图标可能有效。

screenshot

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

public class InternalFrameIconTest {
  private Component makeUI() {
    JDesktopPane desktop = new JDesktopPane();
    JInternalFrame f1 = makeInternalFrame();
    f1.setLocation(40, 40);
    desktop.add(f1);
    JInternalFrame f2 = makeInternalFrame();
    f2.setLocation(10, 10);
    desktop.add(f2);
    return desktop;
  }

  private static JInternalFrame makeInternalFrame() {
    JInternalFrame f = new JInternalFrame("", true, true, false, true);
    f.setFrameIcon(new HorizontalStrutIcon(16));
    f.setSize(240, 120);
    f.setVisible(true);
    return f;
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(() -> {
      try {
        UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
      } catch (Exception ex) {
        ex.printStackTrace();
        return;
      }
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      frame.getContentPane().add(new InternalFrameIconTest().makeUI());
      frame.setSize(320, 240);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
    });
  }
}

class HorizontalStrutIcon implements Icon {
  private final int width;

  public HorizontalStrutIcon(int width) {
    this.width = width;
  }

  @Override public void paintIcon(Component c, Graphics g, int x, int y) {
    // empty
  }

  @Override public int getIconWidth() {
    return width;
  }

  @Override public int getIconHeight() {
    return 0;
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.