如何在 Java 中為 JDesktopPane 設定調色盤層?
首先,建立一個 JDesktopPane -
JDesktopPane desktopPane = new JDesktopPane();
現在,建立一個內部框架 -
JInternalFrame intFrame = new JInternalFrame("Our Frame", true, true, true, true);
intFrame.setBounds(50, 90, 200, 250);設定 JDesktopPane 的調色盤層,並將內部框架新增到 JDesktopPane -
intFrame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
desktopPane.add(intFrame,JDesktopPane.PALETTE_LAYER);以下是一個為 JDesktopPane 設定調色盤層的示例 -
package my;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
public class SwingDemo {
public static void main(final String[] args) {
JFrame frame = new JFrame("Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JDesktopPane desktopPane = new JDesktopPane();
JInternalFrame intFrame = new JInternalFrame("Our Frame", true, true, true, true);
intFrame.setBounds(50, 90, 200, 250);
intFrame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
desktopPane.add(intFrame,JDesktopPane.PALETTE_LAYER);
JLabel label = new JLabel(intFrame.getTitle(), JLabel.CENTER);
JButton button = new JButton("Demo Button");
intFrame.add(label, BorderLayout.CENTER);
intFrame.add(button, BorderLayout.WEST);
intFrame.setVisible(true);
frame.add(desktopPane, BorderLayout.CENTER);
frame.setSize(600, 500);
frame.setVisible(true);
}
}輸出

最大化內部框架 -

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP