gpt4 book ai didi

java - 通过远程桌面共享查看时,未修饰的 JInternalFrame 会变成修饰的

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:26:26 27 4
gpt4 key购买 nike

我遇到了 JInternalFrame 实现的问题。我使 JInternalFrame 未修饰,这样 JInternalFrame 的标题栏和边框就被移除了。问题出现在以下场景中。

  1. 在 Windows 7 机器上执行程序。

    • 此时 JInternalFrame 仍未修饰。
  2. 使用远程桌面共享访问 Windows 7 计算机另一台机器。

    • 现在内部框架的标题栏和边框变得可见。

此问题仅出现在 Windows 7 计算机中,而不会出现在 Windows XP 中。您可以使用远程桌面共享从另一台 Windows 7 计算机或 Windows XP 计算机访问 Windows 7 计算机。

此外,如果您首先使用远程桌面共享访问计算机,然后执行程序,JInternalFrame 将保持未修饰状态。

重现步骤

第 1 步:在 Windows 7 机器上执行应用程序。

第 2 步:使用远程桌面共享从另一台 Windows 7 或 Windows XP 计算机访问 Windows 7 计算机。

第 3 步:检查应用程序的 GUI

结果:- 未修饰的 JInternalFrame 的标题栏和边框变得可见。

如果有人遇到过这个问题或者有人对此问题有解决方案,请分享您的想法。

下面给出了一个示例代码,您可以使用它来重现此问题。

/*
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle or the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import javax.swing.plaf.basic.BasicInternalFrameUI;

import java.awt.event.*;
import java.awt.*;

/*
* InternalFrameDemo.java requires:
* MyInternalFrame.java
*/
public class InternalFrameDemo extends JFrame
implements ActionListener {
JDesktopPane desktop;

public InternalFrameDemo() {
super("InternalFrameDemo");

//Make the big window be indented 50 pixels from each edge
//of the screen.
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height - inset*2);

//Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
createFrame(); //create first "window"
setContentPane(desktop);
setJMenuBar(createMenuBar());

//Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
}

protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();

//Set up the lone menu.
JMenu menu = new JMenu("Document");
menu.setMnemonic(KeyEvent.VK_D);
menuBar.add(menu);

//Set up the first menu item.
JMenuItem menuItem = new JMenuItem("New");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.ALT_MASK));
menuItem.setActionCommand("new");
menuItem.addActionListener(this);
menu.add(menuItem);

//Set up the second menu item.
menuItem = new JMenuItem("Quit");
menuItem.setMnemonic(KeyEvent.VK_Q);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_Q, ActionEvent.ALT_MASK));
menuItem.setActionCommand("quit");
menuItem.addActionListener(this);
menu.add(menuItem);

return menuBar;
}

//React to menu selections.
public void actionPerformed(ActionEvent e) {
if ("new".equals(e.getActionCommand())) { //new
createFrame();
} else { //quit
quit();
}
}

//Create a new internal frame.
protected void createFrame() {
MyInternalFrame frame = new MyInternalFrame();
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}

//Quit the application.
protected void quit() {
System.exit(0);
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
InternalFrameDemo frame = new InternalFrameDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Display the window.
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}

/* Used by InternalFrameDemo.java. */
@SuppressWarnings("serial")
class MyInternalFrame extends JInternalFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;

public MyInternalFrame() {
super("Document #" + (++openFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable

//...Create the GUI and put it in the window...

//...Then set the window size or call pack...
setSize(300,300);
// Undecorating the internal frame
BasicInternalFrameTitlePane titlePane =
(BasicInternalFrameTitlePane) ((BasicInternalFrameUI) this.getUI()).
getNorthPane();
this.remove(titlePane);
this.setBorder(null);
//Set the window's location.
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
}
}

最佳答案

对于 InternalFrame 实例,您需要将未修饰的属性设置为共享属性而不是 .setUndecorated(true)。

或者试试

JInternalFrame frame = new JInternalFrame("frame", false, false, false, false);
frame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);

关于java - 通过远程桌面共享查看时,未修饰的 JInternalFrame 会变成修饰的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12067691/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com