Example usage for javax.swing UIManager setLookAndFeel

List of usage examples for javax.swing UIManager setLookAndFeel

Introduction

In this page you can find the example usage for javax.swing UIManager setLookAndFeel.

Prototype

@SuppressWarnings("deprecation")
public static void setLookAndFeel(String className) throws ClassNotFoundException, InstantiationException,
        IllegalAccessException, UnsupportedLookAndFeelException 

Source Link

Document

Loads the LookAndFeel specified by the given class name, using the current thread's context class loader, and passes it to setLookAndFeel(LookAndFeel) .

Usage

From source file:cn.labthink.ReadAccess060.java

/**
 * @param args the command line arguments
 *//*  ww w .  j a  va  2s .c om*/
public static void main(String args[]) {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ReadAccess060.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        Logger.getLogger(ReadAccess060.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(ReadAccess060.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedLookAndFeelException ex) {
        Logger.getLogger(ReadAccess060.class.getName()).log(Level.SEVERE, null, ex);
    }
    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            ReadAccess060 ut = new ReadAccess060();
            ut.setVisible(true);

            //                new InfraredSimulator().setVisible(true);
        }
    });
}

From source file:cn.labthink.ReadAccess330.java

/**
 * @param args the command line arguments
 *//*  ww w.j  a  v a  2  s. c  om*/
public static void main(String args[]) {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ReadAccess330.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        Logger.getLogger(ReadAccess330.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(ReadAccess330.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedLookAndFeelException ex) {
        Logger.getLogger(ReadAccess330.class.getName()).log(Level.SEVERE, null, ex);
    }
    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            ReadAccess330 ut = new ReadAccess330();
            ut.setVisible(true);

            //                new InfraredSimulator().setVisible(true);
        }
    });
}

From source file:com.softeffect.primemovers.ui.ClientApplication.java

/**
 * Method called by LoginDialog to notify the sucessful login.
 * /*w w  w.ja va 2s.c  o m*/
 * @param loginInfo
 *            login information, like username, password, ...
 */
public void loginSuccessful(Map loginInfo) {
    MDIFrame mdi = new MDIFrame(this);
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        /* Turn off metal's use of bold fonts */
        UIManager.put("swing.boldMetal", Boolean.FALSE);
        SwingUtilities.updateComponentTreeUI(mdi);
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
}

From source file:de.ailis.xadrian.utils.SwingUtils.java

/**
 * Prepares the theme. The theme can be overridden with the environment
 * variable XADRIAN_SYSTHEME. The default is the system look and feel.
 *///from   ww  w .j  av  a2s . c  o m
public static void prepareTheme() {
    final String theme = Config.getInstance().getTheme();
    if (theme != null) {
        try {
            UIManager.setLookAndFeel(theme);
            installGtkPopupBugWorkaround();
            return;
        } catch (final Exception e) {
            LOG.warn("Can't set theme " + theme + ". Falling back to system look-and-feel. Reason: " + e, e);
        }
    }

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        installGtkPopupBugWorkaround();
    } catch (final Exception e) {
        LOG.warn("Can't set system look-and-feel. " + "Falling back to default. Reason: " + e, e);
    }
}

From source file:components.FrameDemo2.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.// w ww  .  j  a  va2 s. c o m
 */
private static void createAndShowGUI() {
    //Use the Java look and feel.
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) {
    }

    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);

    //Instantiate the controlling class.
    JFrame frame = new JFrame("FrameDemo2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the content pane.
    FrameDemo2 demo = new FrameDemo2();

    //Add components to it.
    Container contentPane = frame.getContentPane();
    contentPane.add(demo.createOptionControls(), BorderLayout.CENTER);
    contentPane.add(demo.createButtonPane(), BorderLayout.PAGE_END);
    frame.getRootPane().setDefaultButton(defaultButton);

    //Display the window.
    frame.pack();
    frame.setLocationRelativeTo(null); //center it
    frame.setVisible(true);
}

From source file:com.freedomotic.jfrontend.MainWindow.java

private void setWindowedMode() {
    this.setVisible(false);
    this.dispose();
    this.setUndecorated(false);
    this.setResizable(true);

    try {/*from w w  w  .  j  a va 2s. co  m*/
        this.getContentPane().removeAll();
    } catch (Exception e) {
        LOG.error("Set window mode exception {}", e.getMessage());
    }

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException ex) {
        LOG.error("Cannot find system look&feel\n", ex.toString());
    } catch (InstantiationException ex) {
        LOG.error("Cannot instantiate system look&feel\n", ex.toString());
    } catch (IllegalAccessException ex) {
        LOG.error("Illegal access to system look&feel\n", ex.toString());
    } catch (UnsupportedLookAndFeelException ex) {
        LOG.error("Unsupported system look&feel\n", ex.toString());
    }

    setDefaultLookAndFeelDecorated(true);
    initComponents();
    this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    setLayout(new BorderLayout());
    desktopPane = new JDesktopPane();
    lstClients = new PluginJList(this);
    frameClient = new JInternalFrame();
    frameClient.setLayout(new BorderLayout());

    JScrollPane clientScroll = new JScrollPane(lstClients);
    frameClient.add(clientScroll, BorderLayout.CENTER);
    frameClient.setTitle(i18n.msg("loaded_plugins"));
    frameClient.setResizable(true);
    frameClient.setMaximizable(true);
    frameMap = new JInternalFrame();
    setMapTitle("");
    frameMap.setMaximizable(true);
    frameMap.setResizable(true);
    desktopPane.add(frameMap);
    desktopPane.add(frameClient);
    frameClient.moveToFront();
    frameClient.setVisible(auth.isPermitted("plugins:read"));
    desktopPane.moveToFront(this);
    this.getContentPane().add(desktopPane);

    try {
        frameClient.setSelected(true);
    } catch (PropertyVetoException ex) {
        LOG.error(Freedomotic.getStackTraceInfo(ex));
    }

    EnvironmentLogic previousEnv = api.environments().findAll().get(0);

    if (drawer != null) {
        previousEnv = drawer.getCurrEnv();
    }

    initializeRenderer(previousEnv);
    drawer = master.createRenderer(previousEnv);

    if (drawer != null) {
        setDrawer(drawer);
        ResourcesManager.clear();
    } else {
        LOG.error("Unable to create a drawer to render the environment on the desktop frontend");
    }

    this.setTitle("Freedomotic " + Info.getLicense() + " - www.freedomotic.com");
    this.setSize(1100, 700);
    centerFrame(this);
    frameClient.moveToFront();
    frameMap.moveToFront();
    optimizeFramesDimension();
    drawer.repaint();
    lstClients.update();
    frameClient.setVisible(auth.isPermitted("plugins:read"));
    frameMap.setVisible(auth.isPermitted("environments:read"));
    setEditMode(false);
    this.setVisible(true);
    isFullscreen = false;

}

From source file:atlas.kingj.roi.FrmMain.java

/**
 * Launch the application./*from  w w  w .  ja va  2 s. co m*/
 */
public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Throwable e) {
        e.printStackTrace();
    }
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                window = new FrmMain();
                window.frmTitanRoiCalculator.setVisible(true);
                window.btnNewMachine.requestFocusInWindow();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:EditorPaneExample19.java

public static void main(String[] args) {
    try {/* w w  w  .j  av  a2s  . c  o  m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new EditorPaneExample19();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.setSize(500, 400);
    f.setVisible(true);
}

From source file:bdsup2sub.BDSup2Sub.java

private static void setupGUI() {
    try {//ww w. ja  v a 2 s  . co  m
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        // ignore
    }

    if (PlatformUtils.isLinux()) {
        applyGtkThemeWorkarounds();
    }

    if (PlatformUtils.isMac()) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", Constants.APP_NAME);
    }
}

From source file:com.imag.nespros.gui.plugin.GraphEditor.java

/**
 * create an instance of a simple graph with popup controls to create a
 * graph.//from w w w. j a v a 2s  .c om
 *
 */
private GraphEditor(Simulation s) {
    simu = s;
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex);
    }
    // create a simple graph for the demo
    graph = Topology.getInstance().getGraph();
    this.layout = new StaticLayout<Device, ComLink>(graph, new Transformer<Device, Point2D>() {
        @Override
        public Point2D transform(Device v) {
            Point2D p = new Point2D.Double(v.getX(), v.getY());
            return p;
        }
    }, new Dimension(600, 600));

    vv = new VisualizationViewer<Device, ComLink>(layout);
    vv.setBackground(Color.white);

    final Transformer<Device, String> vertexLabelTransformer = new Transformer<Device, String>() {
        @Override
        public String transform(Device d) {
            return d.getDeviceName();
        }
    };

    //vv.getRenderContext().setVertexLabelTransformer(MapTransformer.<Device, String>getInstance(
    //      LazyMap.<Device, String>decorate(new HashMap<Device, String>(), new ToStringLabeller<Device>())));
    vv.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer);
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<ComLink, String>() {
        @Override
        public String transform(ComLink link) {
            return (link.getID() + ", " + link.getLatency());
        }
    });
    //float dash[] = {0.1f};
    //final Stroke edgeStroke = new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 1.0f);
    final Stroke edgeStroke = new BasicStroke(3.0f);
    final Transformer<ComLink, Stroke> edgeStrokeTransformer = new Transformer<ComLink, Stroke>() {
        @Override
        public Stroke transform(ComLink l) {
            return edgeStroke;
        }
    };
    Transformer<ComLink, Paint> edgePaint = new Transformer<ComLink, Paint>() {
        public Paint transform(ComLink l) {
            if (l.isDown()) {
                return Color.RED;
            } else {
                return Color.BLACK;
            }
        }
    };
    vv.getRenderContext().setEdgeDrawPaintTransformer(edgePaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());
    vv.getRenderContext().setVertexIconTransformer(new CustomVertexIconTransformer());
    vv.getRenderContext().setVertexShapeTransformer(new CustomVertexShapeTransformer());

    vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {

        @Override
        public void paint(Graphics grphcs) {

            for (Device d : Topology.getInstance().getGraph().getVertices()) {
                int size = d.getOperators().size();
                MyLayeredIcon icon = d.getIcon();
                //if(icon == null) continue;
                icon.removeAll();
                if (size > 0) {
                    // the vertex icon                        
                    // Let's create the annotation image to be added to icon..
                    BufferedImage image = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
                    Graphics2D g = image.createGraphics();
                    g.setColor(Color.ORANGE);
                    g.fillOval(0, 0, 20, 20);
                    g.setColor(Color.BLACK);
                    g.drawString(size + "", 5, 13);
                    g.dispose();
                    ImageIcon img = new ImageIcon(image);
                    //Dimension id = new Dimension(icon.getIconWidth(), icon.getIconHeight());
                    //double x = vv.getModel().getGraphLayout().transform(d).getX();
                    //x -= (icon.getIconWidth() / 2);
                    //double y = vv.getModel().getGraphLayout().transform(d).getY();
                    //y -= (icon.getIconHeight() / 2);
                    //grphcs.drawImage(image, (int) Math.round(x), (int) Math.round(y), null);
                    icon.add(img);
                }
            }
        }

        @Override
        public boolean useTransform() {
            return false;
        }
    });

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    Factory<Device> vertexFactory = DeviceFactory.getInstance();
    Factory<ComLink> edgeFactory = ComLinkFactory.getInstance();

    final EditingModalGraphMouse<Device, ComLink> graphMouse = new EditingModalGraphMouse<>(
            vv.getRenderContext(), vertexFactory, edgeFactory);

    // Trying out our new popup menu mouse plugin...
    PopupVertexEdgeMenuMousePlugin myPlugin = new PopupVertexEdgeMenuMousePlugin();
    // Add some popup menus for the edges and vertices to our mouse plugin.
    JPopupMenu edgeMenu = new MyMouseMenus.EdgeMenu(frame);
    JPopupMenu vertexMenu = new MyMouseMenus.VertexMenu(frame);
    myPlugin.setEdgePopup(edgeMenu);
    myPlugin.setVertexPopup(vertexMenu);
    graphMouse.remove(graphMouse.getPopupEditingPlugin()); // Removes the existing popup editing plugin

    graphMouse.add(myPlugin); // Add our new plugin to the mouse  
    // AnnotatingGraphMousePlugin<Device,ComLink> annotatingPlugin =
    //   new AnnotatingGraphMousePlugin<>(vv.getRenderContext());
    //graphMouse.add(annotatingPlugin);
    // the EditingGraphMouse will pass mouse event coordinates to the
    // vertexLocations function to set the locations of the vertices as
    // they are created
    //        graphMouse.setVertexLocations(vertexLocations);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    //final ImageAtEdgePainter<String, String> imageAtEdgePainter = 
    //  new ImageAtEdgePainter<String, String>(vv, edge, image);
    final ScalingControl scaler = new CrossoverScalingControl();
    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JButton help = new JButton("Help");
    help.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(vv, instructions);
        }
    });
    JButton deploy = new JButton("Deploy");
    deploy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // OPMapping algo here
            if (simu == null) {
                return;
            }
            GraphUtil<Device, ComLink> util = new GraphUtil<>();
            for (EventProducer p : simu.getProducers()) {
                if (!p.isMapped()) {
                    JOptionPane.showMessageDialog(frame,
                            "Cannot map operators. Please deploy the producer: " + p.getName());
                    return;
                }
            }
            for (EventConsumer c : simu.getConsumers()) {
                if (!c.isMapped()) {
                    JOptionPane.showMessageDialog(frame,
                            "Cannot map operators. Please deploy the consumer: " + c.getName());
                    return;
                }
                System.out.println("-- Operator placement algorithm Greedy: " + c.getName() + " --");
                Solution init = util.initialMapping(c.getGraph());
                System.out.println(c.getGraph() + "\nInitial Mapping: " + init);
                OperatorMapping mapper = new OperatorMapping();
                long T1, T2;
                System.out.println("--- OpMapping Algo Greedy --- ");
                T1 = System.currentTimeMillis();
                Solution solution = mapper.opMapping(c.getGraph(), Topology.getInstance().getGraph(), init);
                T2 = System.currentTimeMillis();
                System.out.println(solution);
                System.out.println("Solution founded in: " + (T2 - T1) + " ms");
            }
            //                Solution init = util.initialMapping(EPGraph.getInstance().getGraph());
            //                System.out.println("Initial Mapping: " + init);
            //                OperatorMapping mapper = new OperatorMapping();
            //                long T1, T2;
            //                System.out.println("--- OpMapping Algo Greedy --- ");
            //                T1 = System.currentTimeMillis();
            //                Solution solution = mapper.opMapping(EPGraph.getInstance().getGraph(),
            //                        Topology.getInstance().getGraph(), init);
            //                T2 = System.currentTimeMillis();
            //                System.out.println(solution);
            //                System.out.println("Solution founded in: " + (T2 - T1) + " ms");
            vv.repaint();
        }
    });
    JButton run = new JButton("Run");
    run.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // run the simulation here
            System.out.println("Setting the simulation...");
            for (EventConsumer c : simu.getConsumers()) {

                for (EPUnit op : c.getGraph().getVertices()) {
                    if (op.isMapped()) {
                        op.openIOchannels();
                    } else {
                        JOptionPane.showMessageDialog(frame, "Cannot run, undeployed operators founded.");
                        return;
                    }
                }
            }
            //ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
            System.out.println("Running the simulation...");
            //scheduledExecutorService.execute(runner);
            for (Device device : Topology.getInstance().getGraph().getVertices()) {
                if (!device.isAlive()) {
                    device.start();
                }
            }
            for (ComLink link : Topology.getInstance().getGraph().getEdges()) {
                if (!link.isAlive()) {
                    link.start();
                }
            }
            for (EventConsumer c : simu.getConsumers()) {
                for (EPUnit op : c.getGraph().getVertices()) {
                    if (op.isMapped() && op.getDevice() != null && !op.isAlive()) {
                        op.start();
                    }
                }
            }

        }
    });
    AnnotationControls<Device, ComLink> annotationControls = new AnnotationControls<Device, ComLink>(
            graphMouse.getAnnotatingPlugin());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 30, 0);
    slider.setMinorTickSpacing(5);
    slider.setMajorTickSpacing(30);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.setLabelTable(slider.createStandardLabels(15));
    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider slider = (JSlider) e.getSource();
            if (!slider.getValueIsAdjusting()) {
                speedSimulation(slider.getValue());
            }
        }
    });
    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    JComboBox modeBox = graphMouse.getModeComboBox();
    controls.add(modeBox);
    controls.add(annotationControls.getAnnotationsToolBar());
    controls.add(slider);
    controls.add(deploy);
    controls.add(run);
    controls.add(help);
    content.add(controls, BorderLayout.SOUTH);
    /* Custom JPanels can be added here  */
    //
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //final GraphEditor demo = new GraphEditor();

}