Here you can find the source of removeCloseButton(Component comp)
public static void removeCloseButton(Component comp)
//package com.java2s; /*//from ww w . j a va 2 s. co m * Argus Open Source * Software to apply Statistical Disclosure Control techniques * * Copyright 2014 Statistics Netherlands * * This program is free software; you can redistribute it and/or * modify it under the terms of the European Union Public Licence * (EUPL) version 1.1, as published by the European Commission. * * You can find the text of the EUPL v1.1 on * https://joinup.ec.europa.eu/software/page/eupl/licence-eupl * * This software is distributed on an "AS IS" basis without * warranties or conditions of any kind, either express or implied. */ import java.awt.Component; import java.awt.Container; import javax.swing.AbstractButton; import javax.swing.Action; import javax.swing.JMenu; public class Main { /** * Only works for default look and feel, where Swing creates a real close * button. In other look and feels close buttons are handled by the native * OS and are not part of the Swing component hierarchy. */ public static void removeCloseButton(Component comp) { if (comp instanceof JMenu) { Component[] children = ((JMenu) comp).getMenuComponents(); for (int i = 0; i < children.length; ++i) { removeCloseButton(children[i]); } } else if (comp instanceof AbstractButton) { Action action = ((AbstractButton) comp).getAction(); String cmd = (action == null) ? "" : action.toString(); if (cmd.contains("CloseAction")) { comp.getParent().remove(comp); } } else if (comp instanceof Container) { Component[] children = ((Container) comp).getComponents(); for (int i = 0; i < children.length; ++i) { removeCloseButton(children[i]); } } } }