[英]Can I create a Window in Java with no caption buttons?
是否可以在Java中創建某種具有框架和邊框但沒有標題按鈕(最小化,恢復,關閉)的Window對象。
當然,我不能使用undecorated
設置。 此外,窗口需要:
System
外觀 這是一個例子:
這是關於
使用復合邊框進行未修飾的JDialog
,然后您可以創建來自Native OS的similair或更好的邊框
使用GradientPaint
創建JPanel
(或JLabel#opaque(true)
)
或者(更好的non_focusable
==我的觀點) JLabel
准備了Icon
添加到JPanel
/ JLabel
組件移動器/組件調整大小 (注意,不要永遠不要將這兩個代碼混合在一起)@camickr
將Alpha Transparency
設置為在JPanel
/ JLabel
繪畫,以獲得出色的look and feel
最簡單的方法就是JMenuBar
最簡潔的答案是不。
可能更長的答案是,但您需要調查JNI / JNA實現
試試這個小例子。 它將從JFrame中刪除(不僅禁用)最小化,最大化和關閉按鈕。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Example {
public void buildGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame();
frame.setResizable(false);
removeButtons(frame);
JPanel panel = new JPanel(new GridBagLayout());
JButton button = new JButton("Exit");
panel.add(button,new GridBagConstraints());
frame.getContentPane().add(panel);
frame.setSize(400,300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent a){
System.exit(0);
}
});
}
public void removeButtons(Component comp) {
if(comp instanceof AbstractButton) {
comp.getParent().remove(comp);
}
if (comp instanceof Container) {
Component[] comps = ((Container)comp).getComponents();
for(int x=0, y=comps.length; x<y; x++) {
removeButtons(comps[x]);
}
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Example().buildGUI();
}
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.