下面列出了javax.swing.JDialog#getContentPane ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Help(URL contents, MessageDialogs messageDialogs,
String title)
{
m_messageDialogs = messageDialogs;
m_contents = contents;
Container contentPane;
if (Platform.isMac())
{
JDialog dialog = new JDialog((Frame)null, title);
contentPane = dialog.getContentPane();
m_window = dialog;
}
else
{
JFrame frame = new JFrame(title);
GuiUtil.setGoIcon(frame);
contentPane = frame.getContentPane();
m_window = frame;
}
JPanel panel = new JPanel(new BorderLayout());
contentPane.add(panel);
panel.add(createButtons(), BorderLayout.NORTH);
m_editorPane = new JEditorPane();
m_editorPane.setEditable(false);
m_editorPane.addHyperlinkListener(this);
int width = GuiUtil.getDefaultMonoFontSize() * 50;
int height = GuiUtil.getDefaultMonoFontSize() * 60;
JScrollPane scrollPane =
new JScrollPane(m_editorPane,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
if (Platform.isMac())
// Default Apple L&F uses no border, but Quaqua 3.7.4 does
scrollPane.setBorder(null);
scrollPane.setPreferredSize(new Dimension(width, height));
panel.add(scrollPane, BorderLayout.CENTER);
m_window.pack();
loadURL(m_contents);
appendHistory(m_contents);
}
/**
* Wraps the content pane of the dialog with this instance
*
* @param dialog
* a fully configured dialog
*/
public void addToDialog(JDialog dialog) {
if (!(dialog.getContentPane() instanceof DeprecationWarning) && originalContentPane == null) {
originalContentPane = dialog.getContentPane();
add(originalContentPane, BorderLayout.CENTER);
dialog.setContentPane(this);
}
}
/**
* Centers the dialog over the given parent component. Also, creates a
* semi-transparent panel behind the dialog to mask the parent content.
* The title of the dialog is displayed in a custom fashion over the dialog
* panel, and a rectangular shadow is placed behind the dialog.
*/
public static void createDialogBackPanel(JDialog dialog, Component parent) {
dialog.setBackground(new Color(255, 255, 255, 64));
DialogBackPanel newContentPane = new DialogBackPanel(dialog.getContentPane(), dialog.getTitle());
dialog.setContentPane(newContentPane);
dialog.setSize(parent.getSize());
dialog.setLocation(parent.getLocationOnScreen());
}
private static void showInDialog(JComponent panel) {
JDialog dialog = new JDialog();
Container contentPane = dialog.getContentPane();
((JComponent) contentPane).setBorder(BorderFactory.createEmptyBorder(
10, 10, 10, 10));
contentPane.add(panel);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}
protected void setEnabledComponentsWhileLoading(boolean enabled) {
JDialog dialog = getJDialog();
JPanel dialogContentPanel = (JPanel)dialog.getContentPane();
Stack<JComponent> stack = new Stack<JComponent>();
stack.push(dialogContentPanel);
while (!stack.isEmpty()) {
JComponent component = stack.pop();
component.setEnabled(enabled);
int childrenCount = component.getComponentCount();
for (int i=0; i<childrenCount; i++) {
Component child = component.getComponent(i);
if (child instanceof JComponent) {
JComponent childComponent = (JComponent) child;
boolean found = false;
for (int k=0; k<this.componentsAllwaysEnabled.size(); k++) {
if (childComponent == this.componentsAllwaysEnabled.get(k)) {
found = true;
}
}
if (!found) {
// add the component in the stack to be enabled/disabled
stack.push(childComponent);
}
}
}
}
}
public static final void download(Library library, Release release) {
LibraryUpdater lib = new LibraryUpdater(library, release);
if (GraphicsEnvironment.isHeadless()) {
FutureTask<Object> task = new FutureTask<>(lib, null);
QUEUE.submit(task);
try {
task.get();
} catch (Exception exception) {
Log.error(exception);
}
} else {
// Close any open files that come from the library
Workspace workspace = Workspace.get();
Path prefix = library.getPath();
String title = library.getTitle();
for (Dockable dockable : workspace.getDock().getDockables()) {
if (dockable instanceof DataFileDockable) {
DataFileDockable dfd = (DataFileDockable) dockable;
Path path = dfd.getBackingFile();
if (path != null && path.toAbsolutePath().startsWith(prefix)) {
if (dfd.mayAttemptClose()) {
if (!dfd.attemptClose()) {
JOptionPane.showMessageDialog(null, String.format(I18n.Text("GCS %s update was canceled."), title), I18n.Text("Canceled!"), JOptionPane.INFORMATION_MESSAGE);
return;
}
}
}
}
}
// Put up a progress dialog
JDialog dialog = new JDialog(workspace, String.format(I18n.Text("Update %s"), title), true);
dialog.setResizable(false);
dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
dialog.setUndecorated(true);
JComponent content = (JComponent) dialog.getContentPane();
content.setLayout(new BorderLayout());
content.setBorder(new CompoundBorder(new LineBorder(), new EmptyBorder(10)));
content.add(new JLabel(String.format(I18n.Text("Downloading and installing the %s…"), title)), BorderLayout.NORTH);
JProgressBar bar = new JProgressBar();
bar.setIndeterminate(true);
content.add(bar);
dialog.pack();
dialog.setLocationRelativeTo(workspace);
lib.mDialog = dialog;
QUEUE.submit(lib);
dialog.setVisible(true);
}
}