Thy*_*hys 11 java macos swing jdialog
我目前正在使用此代码创建JDialog;
package com.kamuara.reposync.window;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
public class SheetDialog {
private JFrame _windowFrame;
public static void main(String[] args) {
System.setProperty("apple.awt.documentModalSheet", "true");
System.setProperty("apple.awt.brushMetalLook", "true");
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
new SheetDialog();
} catch (Exception e) {
e.printStackTrace();
}
}
public SheetDialog() {
_windowFrame = new JFrame();
_windowFrame.setResizable(false);
_windowFrame.setBounds(100, 100, 451, 320);
_windowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_windowFrame.getContentPane().setLayout(null);
_windowFrame.setVisible(true);
JButton showDialogButton = new JButton("Show Dialog");
showDialogButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showSheetDialog(_windowFrame, "Test", "This should be a sheet dialog", "Oke");
}
});
showDialogButton.setBounds(328, 263, 117, 29);
_windowFrame.getContentPane().add(showDialogButton);
}
public void showSheetDialog(JFrame owner, String title, String message, String button) {
final JDialog messageDialog = new JDialog(owner, title, Dialog.ModalityType.DOCUMENT_MODAL);
messageDialog.setBounds(30, 0, owner.getWidth() - 60, 130);
// TODO: only when os is osx
messageDialog.getRootPane().putClientProperty("apple.awt.documentModalSheet", "true");
messageDialog.setLayout(null);
int offsetX = 25;
JLabel titleLabel = new JLabel(title);
titleLabel.setFont(new Font("Lucida Grande", Font.BOLD, 13));
titleLabel.setBounds(offsetX, 10, 100, 25);
messageDialog.getContentPane().add(titleLabel);
JLabel messageLabel = new JLabel(message);
messageLabel.setVerticalTextPosition(JLabel.TOP);
messageLabel.setHorizontalTextPosition(JLabel.LEFT);
messageLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 11));
messageLabel.setBounds(offsetX, 10, messageDialog.getWidth() - 10, messageDialog.getHeight() - 60);
messageDialog.getContentPane().add(messageLabel);
JButton okButton = new JButton(button);
okButton.setBounds(messageDialog.getWidth() - 105, messageDialog.getHeight() - 35, 100, 25);
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
messageDialog.dispose();
}
});
messageDialog.getContentPane().add(okButton);
messageDialog.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
我以前使用Java 6编译应用程序并设置clientProperty apple.awt.documentModalSheet完美地在OSX上将对话框显示为"Sheet"但现在我开始使用Java 7(更新25)并且对话框不再显示为Sheet.我似乎无法找到任何关于此的更新文档.他们有没有改变这个?我怎么解决这个问题?使用Sheet而不是对话框,当前界面设计看起来更好.
更新
我发现以下错误报告似乎与我遇到的问题相同;
http://bugs.sun.com/view_bug.do?bug_id=8010197
有谁知道如何解决这个问题?我已经查看了像QuaQua这样的库,但我不想使用任何库,因为我只想要Sheet功能.
更新2
我尝试过QuaQua,但是在使用Java 7进行编译时,库目前存在完全相同的问题.任何解决方法?
更新3
用工作样本替换代码(http://pastebin.com/PJ8VGdPb)
更新4
发现SWT有一个名为SWT.SHEET的Shell类的样式,它仍然可以在Java7中运行,我不喜欢使用类似SWT的库,但它似乎是唯一的解决方案.
据我所知,Apple 尚未正式发布 JDK 7 版本。Apple 针对 OS X 优化的最新版本 JDK 仍然是 JDK 6。这也是 Java 更新通过 AppStore 更新选项卡进行的原因。这些更新并非直接来自 Oracle。
如果您直接从 Oracle 下载 JDK 7,这是一个更通用、未调整的版本。
所以,我认为你只需要等待 Apple 发布他们的 OS X 优化的 JDK 7 即可。
当我从 Oracle 下载时,我遇到了很多 OS X 功能无法运行的情况:
| 归档时间: |
|
| 查看次数: |
977 次 |
| 最近记录: |