Java Utililty Methods Desktop

List of utility methods to do Desktop

Description

The list of methods to do Desktop are organized into topic(s).

Method

voidbrowse(File file, Component component)
Browse to a folder.
try {
    Desktop.getDesktop().browse(new URL("file://" + file.getAbsolutePath()).toURI());
} catch (IOException e) {
    JOptionPane.showMessageDialog(component,
            "Unable to open '" + file.getAbsolutePath() + "'. Maybe it doesn't exist?", "Open failed",
            JOptionPane.ERROR_MESSAGE);
} catch (URISyntaxException e) {
JMenubuild(File appDir)
build
JMenu helpMenu = new JMenu("Help");
JMenu manuals = buildManualsMenu(appDir);
if (manuals.getItemCount() > 0) {
    helpMenu.add(manuals);
    helpMenu.addSeparator();
helpMenu.add(buildWebsiteMenuItem());
helpMenu.add(buildForumMenuItem());
...
voidcenterOnDesktop(Component comp, Component parent, boolean bAdjust)
Centers a child window or dialog on a JDesktopPane.
if (!(parent instanceof JDesktopPane)) {
    center(comp, parent, bAdjust);
} else {
    JViewport jvp = (JViewport) parent.getParent();
    final Dimension dimParentSize = jvp.getSize();
    final Point pParentLocation = jvp.getViewPosition();
    placeComponent(comp, pParentLocation, dimParentSize, bAdjust);
booleanopenFile(String filePath)
open File
File exec = new File(filePath);
if (exec.exists()) {
    try {
        Desktop.getDesktop().open(exec);
    } catch (IOException e) {
        logError(e);
        return false;
} else {
    showMessage("file_not_found", filePath);
    return false;
return true;