List of usage examples for javax.swing UIManager getLookAndFeel
public static LookAndFeel getLookAndFeel()
null
. From source file:jatoo.app.App.java
public App(final String title) { this.title = title; ///*from w w w . ja v a 2 s .c om*/ // load properties properties = new AppProperties(new File(getWorkingDirectory(), "app.properties")); properties.loadSilently(); // // resources texts = new ResourcesTexts(getClass(), new ResourcesTexts(App.class)); images = new ResourcesImages(getClass(), new ResourcesImages(App.class)); // // create & initialize the window if (isDialog()) { window = new JDialog((Frame) null, getTitle()); if (isUndecorated()) { ((JDialog) window).setUndecorated(true); ((JDialog) window).setBackground(new Color(0, 0, 0, 0)); } ((JDialog) window).setResizable(isResizable()); } else { window = new JFrame(getTitle()); if (isUndecorated()) { ((JFrame) window).setUndecorated(true); ((JFrame) window).setBackground(new Color(0, 0, 0, 0)); } ((JFrame) window).setResizable(isResizable()); } window.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { System.exit(0); } @Override public void windowIconified(final WindowEvent e) { if (isHideWhenMinimized()) { hide(); } } }); // // set icon images // is either all icons from initializer package // or all icons from app package List<Image> windowIconImages = new ArrayList<>(); String[] windowIconImagesNames = new String[] { "016", "020", "022", "024", "032", "048", "064", "128", "256", "512" }; for (String size : windowIconImagesNames) { try { windowIconImages.add(new ImageIcon(getClass().getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } if (windowIconImages.size() == 0) { for (String size : windowIconImagesNames) { try { windowIconImages .add(new ImageIcon(App.class.getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } } window.setIconImages(windowIconImages); // // this is the place for to call init method // after all local components are created // from now (after init) is only configuration init(); // // set content pane ( and ansure transparency ) JComponent contentPane = getContentPane(); contentPane.setOpaque(false); ((RootPaneContainer) window).setContentPane(contentPane); // // pack the window right after the set of the content pane window.pack(); // // center window (as default in case restore fails) // and try to restore the last location window.setLocationRelativeTo(null); window.setLocation(properties.getLocation(window.getLocation())); if (!isUndecorated()) { if (properties.getLastUndecorated(isUndecorated()) == isUndecorated()) { if (isResizable() && isSizePersistent()) { final String currentLookAndFeel = String.valueOf(UIManager.getLookAndFeel()); if (properties.getLastLookAndFeel(currentLookAndFeel).equals(currentLookAndFeel)) { window.setSize(properties.getSize(window.getSize())); } } } } // // fix location if out of screen Rectangle intersection = window.getGraphicsConfiguration().getBounds().intersection(window.getBounds()); if ((intersection.width < window.getWidth() * 1 / 2) || (intersection.height < window.getHeight() * 1 / 2)) { UIUtils.setWindowLocationRelativeToScreen(window); } // // restore some properties setAlwaysOnTop(properties.isAlwaysOnTop()); setHideWhenMinimized(properties.isHideWhenMinimized()); setTransparency(properties.getTransparency(transparency)); // // null is also a good value for margins glue gaps (is [0,0,0,0]) Insets marginsGlueGaps = getMarginsGlueGaps(); if (marginsGlueGaps == null) { marginsGlueGaps = new Insets(0, 0, 0, 0); } // // glue to margins on Ctrl + ARROWS if (isGlueToMarginsOnCtrlArrows()) { UIUtils.setActionForCtrlDownKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginBottom(window, marginsGlueGaps.bottom)); UIUtils.setActionForCtrlLeftKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginLeft(window, marginsGlueGaps.left)); UIUtils.setActionForCtrlRightKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginRight(window, marginsGlueGaps.right)); UIUtils.setActionForCtrlUpKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginTop(window, marginsGlueGaps.top)); } // // drag to move ( when provided component is not null ) JComponent dragToMoveComponent = getDragToMoveComponent(); if (dragToMoveComponent != null) { // // move the window by dragging the UI component int marginsGlueRange = Math.min(window.getGraphicsConfiguration().getBounds().width, window.getGraphicsConfiguration().getBounds().height); marginsGlueRange /= 60; marginsGlueRange = Math.max(marginsGlueRange, 15); UIUtils.forwardDragAsMove(dragToMoveComponent, window, marginsGlueRange, marginsGlueGaps); // // window popup dragToMoveComponent.addMouseListener(new MouseAdapter() { public void mouseReleased(final MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { windowPopup = getWindowPopup(e.getLocationOnScreen()); windowPopup.setVisible(true); } } }); // // always dispose the popup when window lose the focus window.addFocusListener(new FocusAdapter() { public void focusLost(final FocusEvent e) { if (windowPopup != null) { windowPopup.setVisible(false); windowPopup = null; } } }); } // // tray icon if (hasTrayIcon()) { if (SystemTray.isSupported()) { Image trayIconImage = windowIconImages.get(0); Dimension trayIconSize = SystemTray.getSystemTray().getTrayIconSize(); for (Image windowIconImage : windowIconImages) { if (Math.abs(trayIconSize.width - windowIconImage.getWidth(null)) < Math .abs(trayIconImage.getWidth(null) - windowIconImage.getWidth(null))) { trayIconImage = windowIconImage; } } final TrayIcon trayIcon = new TrayIcon(trayIconImage); trayIcon.setPopupMenu(getTrayIconPopup()); trayIcon.addMouseListener(new MouseAdapter() { public void mouseClicked(final MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() >= 2) { if (window.isVisible()) { hide(); } else { show(); } } } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException e) { logger.error( "unexpected exception trying to add the tray icon ( the desktop system tray is missing? )", e); } } else { logger.error("the system tray is not supported on the current platform"); } } // // hidden or not if (properties.isVisible()) { window.setVisible(true); } // // close the splash screen // if there is one try { SplashScreen splash = SplashScreen.getSplashScreen(); if (splash != null) { splash.close(); } } catch (UnsupportedOperationException e) { getLogger().info("splash screen not supported", e); } // // add shutdown hook for #destroy() Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { App.this.destroy(); } }); // // after init afterInit(); }
From source file:ExtendedTableCellRenderer.java
public void paint(Graphics g) { super.paint(g); if (underlined) { Insets i = getInsets();//from w w w .j a v a 2 s.c o m FontMetrics fm = g.getFontMetrics(); Rectangle textRect = new Rectangle(); Rectangle viewRect = new Rectangle(i.left, i.top, getWidth() - (i.right + i.left), getHeight() - (i.bottom + i.top)); SwingUtilities.layoutCompoundLabel(this, fm, getText(), getIcon(), getVerticalAlignment(), getHorizontalAlignment(), getVerticalTextPosition(), getHorizontalTextPosition(), viewRect, new Rectangle(), textRect, getText() == null ? 0 : ((Integer) UIManager.get("Button.textIconGap")).intValue()); int offset = 2; if (UIManager.getLookAndFeel().isNativeLookAndFeel() && System.getProperty("os.name").startsWith("Windows")) { offset = 1; } g.fillRect(textRect.x + ((Integer) UIManager.get("Button.textShiftOffset")).intValue(), textRect.y + fm.getAscent() + ((Integer) UIManager.get("Button.textShiftOffset")).intValue() + offset, textRect.width, 1); } }
From source file:com.igormaznitsa.sciareto.ui.MainFrame.java
public MainFrame(@Nonnull @MustNotContainNull final String... args) { super();/*from w w w .j ava2s.co m*/ initComponents(); this.stackPanel = new JPanel(); this.stackPanel.setFocusable(false); this.stackPanel.setOpaque(false); this.stackPanel.setBorder(BorderFactory.createEmptyBorder(32, 32, 16, 32)); this.stackPanel.setLayout(new BoxLayout(this.stackPanel, BoxLayout.Y_AXIS)); final JPanel glassPanel = (JPanel) this.getGlassPane(); glassPanel.setOpaque(false); this.setGlassPane(glassPanel); glassPanel.setLayout(new BorderLayout(8, 8)); glassPanel.add(Box.createGlue(), BorderLayout.CENTER); final JPanel ppanel = new JPanel(new BorderLayout(0, 0)); ppanel.setFocusable(false); ppanel.setOpaque(false); ppanel.setCursor(null); ppanel.add(this.stackPanel, BorderLayout.SOUTH); glassPanel.add(ppanel, BorderLayout.EAST); this.stackPanel.add(Box.createGlue()); glassPanel.setVisible(false); this.setTitle("Scia Reto"); setIconImage(UiUtils.loadImage("logo256x256.png")); this.stateless = args.length > 0; final MainFrame theInstance = this; this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(@Nonnull final WindowEvent e) { if (doClosing()) { dispose(); } } }); this.tabPane = new EditorTabPane(this); this.explorerTree = new ExplorerTree(this); final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(250); splitPane.setResizeWeight(0.0d); splitPane.setLeftComponent(this.explorerTree); splitPane.setRightComponent(this.tabPane); add(splitPane, BorderLayout.CENTER); this.menuOpenRecentProject.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { final File[] lastOpenedProjects = FileHistoryManager.getInstance().getLastOpenedProjects(); if (lastOpenedProjects.length > 0) { for (final File folder : lastOpenedProjects) { final JMenuItem item = new JMenuItem(folder.getName()); item.setToolTipText(folder.getAbsolutePath()); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openProject(folder, false); } }); menuOpenRecentProject.add(item); } } } @Override public void menuDeselected(MenuEvent e) { menuOpenRecentProject.removeAll(); } @Override public void menuCanceled(MenuEvent e) { } }); this.menuOpenRecentFile.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { final File[] lastOpenedFiles = FileHistoryManager.getInstance().getLastOpenedFiles(); if (lastOpenedFiles.length > 0) { for (final File file : lastOpenedFiles) { final JMenuItem item = new JMenuItem(file.getName()); item.setToolTipText(file.getAbsolutePath()); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openFileAsTab(file); } }); menuOpenRecentFile.add(item); } } } @Override public void menuDeselected(MenuEvent e) { menuOpenRecentFile.removeAll(); } @Override public void menuCanceled(MenuEvent e) { } }); if (!this.stateless) { restoreState(); } else { boolean openedProject = false; for (final String filePath : args) { final File file = new File(filePath); if (file.isDirectory()) { openedProject = true; openProject(file, true); } else if (file.isFile()) { openFileAsTab(file); } } if (!openedProject) { //TODO try to hide project panel! } } final LookAndFeel current = UIManager.getLookAndFeel(); final ButtonGroup lfGroup = new ButtonGroup(); final String currentLFClassName = current.getClass().getName(); for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(info.getName()); lfGroup.add(menuItem); if (currentLFClassName.equals(info.getClassName())) { menuItem.setSelected(true); } menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(@Nonnull final ActionEvent e) { try { UIManager.setLookAndFeel(info.getClassName()); SwingUtilities.updateComponentTreeUI(theInstance); PreferencesManager.getInstance().getPreferences().put(Main.PROPERTY_LOOKANDFEEL, info.getClassName()); PreferencesManager.getInstance().flush(); } catch (Exception ex) { LOGGER.error("Can't change LF", ex); } } }); this.menuLookAndFeel.add(menuItem); } }
From source file:com.googlecode.vfsjfilechooser2.plaf.basic.BasicVFSFileChooserUI.java
protected void installIcons(VFSJFileChooser fc) { UIDefaults defaults = UIManager.getLookAndFeel().getDefaults(); directoryIcon = lookupIcon("folder.png"); fileIcon = lookupIcon("file.png"); computerIcon = defaults.getIcon("FileView.computerIcon"); hardDriveIcon = defaults.getIcon("FileView.hardDriveIcon"); floppyDriveIcon = defaults.getIcon("FileView.floppyDriveIcon"); newFolderIcon = lookupIcon("folder_add.png"); upFolderIcon = lookupIcon("go-up.png"); homeFolderIcon = lookupIcon("folder_user.png"); detailsViewIcon = lookupIcon("application_view_detail.png"); listViewIcon = lookupIcon("application_view_list.png"); viewMenuIcon = defaults.getIcon("FileChooser.viewMenuIcon"); }
From source file:jatoo.app.App.java
public void destroy() { //// w ww .ja v a2 s .c o m // save properties properties.setLocation(window.getLocation()); properties.setSize(window.getSize()); properties.setAlwaysOnTop(isAlwaysOnTop()); properties.setTransparency(getTransparency()); properties.setHideWhenMinimized(isHideWhenMinimized()); properties.setVisible(window.isVisible()); properties.setLastLookAndFeel(String.valueOf(UIManager.getLookAndFeel())); properties.setLastUndecorated(isUndecorated()); properties.saveSilently(); }
From source file:core.PlanC.java
public static void showNotification(String mid, int lt, Object... dta) { AplicationException ae = new AplicationException(mid, dta); WebNotificationPopup npop = NotificationManager.showNotification(PlanC.frame, ae.getMessage(), ae.getExceptionIcon());//from w ww. j av a2 s . com // ae.getExceptionIcon(), NotificationOption.accept); npop.setDisplayTime(lt); if (mid.equals("notification.msg00")) { UIManager.getLookAndFeel().provideErrorFeedback(null); } else { newMsg.play(); } }
From source file:SortableTable.java
/** * Creates a new button renderer./*from www . j a v a2 s . c om*/ */ public SortButtonRenderer() { this.pressedColumn = -1; this.useLabels = UIManager.getLookAndFeel().getID().equals("Aqua"); final Border border = UIManager.getBorder("TableHeader.cellBorder"); if (this.useLabels) { this.normalLabel = new JLabel(); this.normalLabel.setHorizontalAlignment(SwingConstants.LEADING); this.ascendingLabel = new JLabel(); this.ascendingLabel.setHorizontalAlignment(SwingConstants.LEADING); this.ascendingLabel.setHorizontalTextPosition(SwingConstants.LEFT); this.ascendingLabel.setIcon(new BevelArrowIcon(BevelArrowIcon.DOWN, false, false)); this.descendingLabel = new JLabel(); this.descendingLabel.setHorizontalAlignment(SwingConstants.LEADING); this.descendingLabel.setHorizontalTextPosition(SwingConstants.LEFT); this.descendingLabel.setIcon(new BevelArrowIcon(BevelArrowIcon.UP, false, false)); this.normalLabel.setBorder(border); this.ascendingLabel.setBorder(border); this.descendingLabel.setBorder(border); } else { this.normalButton = new JButton(); this.normalButton.setMargin(new Insets(0, 0, 0, 0)); this.normalButton.setHorizontalAlignment(SwingConstants.LEADING); this.ascendingButton = new JButton(); this.ascendingButton.setMargin(new Insets(0, 0, 0, 0)); this.ascendingButton.setHorizontalAlignment(SwingConstants.LEADING); this.ascendingButton.setHorizontalTextPosition(SwingConstants.LEFT); this.ascendingButton.setIcon(new BevelArrowIcon(BevelArrowIcon.DOWN, false, false)); this.ascendingButton.setPressedIcon(new BevelArrowIcon(BevelArrowIcon.DOWN, false, true)); this.descendingButton = new JButton(); this.descendingButton.setMargin(new Insets(0, 0, 0, 0)); this.descendingButton.setHorizontalAlignment(SwingConstants.LEADING); this.descendingButton.setHorizontalTextPosition(SwingConstants.LEFT); this.descendingButton.setIcon(new BevelArrowIcon(BevelArrowIcon.UP, false, false)); this.descendingButton.setPressedIcon(new BevelArrowIcon(BevelArrowIcon.UP, false, true)); this.normalButton.setBorder(border); this.ascendingButton.setBorder(border); this.descendingButton.setBorder(border); } }
From source file:org.pegadi.client.ApplicationLauncher.java
protected void setTheme(String theme) { //TODO: fix nullpointerexception log.debug("theme: {}", theme); String lfTheme;/*from w w w. j av a 2 s .c o m*/ if (theme.equalsIgnoreCase("system")) { lfTheme = UIManager.getSystemLookAndFeelClassName(); } else if (theme.equalsIgnoreCase("swing")) { lfTheme = UIManager.getCrossPlatformLookAndFeelClassName(); lfTheme = UIManager.getSystemLookAndFeelClassName(); } else if (theme.equalsIgnoreCase("gtk")) { lfTheme = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"; //DEBUG lfTheme = UIManager.getSystemLookAndFeelClassName(); } else { log.error("Invalid L&F theme"); throw new IllegalArgumentException("'" + theme + "' is not a supported L&F"); } if (!lfTheme.equals(UIManager.getLookAndFeel().getName())) { try { UIManager.setLookAndFeel(lfTheme); } catch (Exception e) { log.warn("Unable to set selected L&F, swapping to a default L&F"); UIManager.LookAndFeelInfo[] installedLF = UIManager.getInstalledLookAndFeels(); try { UIManager.setLookAndFeel(installedLF[0].getClassName()); } catch (Exception e2) { log.error("Unable to load any L&F, exiting", e2); System.exit(-1); } } try { log.debug("attempting to update componenttreeui"); SwingUtilities.updateComponentTreeUI(this.getContentPane()); } catch (Exception swe) { log.error("Unable to update component tree", swe); } } pack(); //Might be the cause of occasional NullpointEx due to system //not being able to locate LookAndFeel }
From source file:com.googlecode.vfsjfilechooser2.VFSJFileChooser.java
/** * Creates and returns a new <code>JDialog</code> wrapping * <code>this</code> centered on the <code>parent</code> * in the <code>parent</code>'s frame. * This method can be overriden to further manipulate the dialog, * to disable resizing, set the location, etc. Example: * <pre>/* w w w . j a v a 2 s . c o m*/ * class MyFileChooser extends VFSJFileChooser { * protected JDialog createDialog(Component parent) throws HeadlessException { * JDialog dialog = super.createDialog(parent); * dialog.setLocation(300, 200); * dialog.setResizable(false); * return dialog; * } * } * </pre> * * @param parent the parent component of the dialog; * can be <code>null</code> * @return a new <code>JDialog</code> containing this instance * @exception HeadlessException if GraphicsEnvironment.isHeadless() * returns true. * @see java.awt.GraphicsEnvironment#isHeadless * @since 1.4 */ protected JDialog createDialog(Component parent) throws HeadlessException { String title = getUI().getDialogTitle(this); putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, title); Window window = null; try { window = SwingUtilities.getWindowAncestor(parent); } catch (Exception ex) { } if (window == null) { if (parent instanceof Window) { window = (Window) parent; } else { window = SHARED_FRAME; } dialog = new JDialog((Frame) window, title, true); } else if (window instanceof Frame) { dialog = new JDialog((Frame) window, title, true); } else { dialog = new JDialog((Dialog) window, title, true); } dialog.setComponentOrientation(this.getComponentOrientation()); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(this, BorderLayout.CENTER); if (JDialog.isDefaultLookAndFeelDecorated()) { boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations(); if (supportsWindowDecorations) { dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG); } } dialog.pack(); dialog.setLocationRelativeTo(parent); return dialog; }
From source file:com.commander4j.util.JUtility.java
public static void adjustForLookandFeel() { LookAndFeel lf = UIManager.getLookAndFeel(); if (lf.getName().equals("Mac OS X")) { Common.LFAdjustWidth = 0;//w w w . ja v a 2 s. c o m Common.LFAdjustHeight = 0; Common.LFTreeMenuAdjustWidth = 13; Common.LFTreeMenuAdjustHeight = 13; System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Commander4j"); } else { Common.LFAdjustWidth = -13; Common.LFAdjustHeight = -13; Common.LFTreeMenuAdjustWidth = 0; Common.LFTreeMenuAdjustHeight = 0; } }