Example usage for javax.swing Icon getIconWidth

List of usage examples for javax.swing Icon getIconWidth

Introduction

In this page you can find the example usage for javax.swing Icon getIconWidth.

Prototype

int getIconWidth();

Source Link

Document

Returns the icon's width.

Usage

From source file:es.emergya.ui.base.plugins.PluggableJTabbedPane.java

private void addFloatingButtons() {
    JButton salir = new JButton();
    salir.addActionListener(new ExitHandler());

    Icon icon = LogicConstants.getIcon("header_button_exit");
    salir.setIcon(icon);/*ww  w .  j  a va 2  s .co  m*/
    if (icon != null)
        if (min_height < icon.getIconHeight())
            min_height = icon.getIconHeight();

    // Aadimos el botn de Salir
    salir.setBounds(this.getWidth() - icon.getIconWidth() - 2, 2, icon.getIconWidth(), icon.getIconHeight());
    salir.setBorderPainted(false);
    PluggableJTabbedPane.this.salir = salir.getBounds();

    // Logo de la empresa
    JLabel logo = new JLabel();
    icon = LogicConstants.getIcon("header_logo_cliente");
    if (min_height < icon.getIconHeight())
        min_height = icon.getIconHeight();

    logo.setIcon(icon);
    logo.setBounds(salir.getBounds().x - icon.getIconWidth() - 2, 2, icon.getIconWidth(), icon.getIconHeight());

    JLabel companyLogo = new JLabel();
    icon = LogicConstants.getIcon("header_logo");
    if (icon != null)
        if (min_height < icon.getIconHeight())
            min_height = icon.getIconHeight();
    companyLogo.setIcon(icon);
    companyLogo.setBounds(logo.getBounds().x - icon.getIconWidth(), 2, icon.getIconWidth(),
            icon.getIconHeight());

    botones_flotantes = new ArrayList<JComponent>();
    addFloatingButton(companyLogo);
    addFloatingButton(logo);
    addFloatingButton(salir);

    repaint();
}

From source file:marytts.tools.voiceimport.DatabaseImportMain.java

protected void setupGUI() {
    // A scroll pane containing one labelled checkbox per component,
    // and a "run selected components" button below.
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridC = new GridBagConstraints();
    getContentPane().setLayout(gridBagLayout);

    JPanel checkboxPane = new JPanel();
    checkboxPane.setLayout(new BoxLayout(checkboxPane, BoxLayout.Y_AXIS));
    //checkboxPane.setPreferredSize(new Dimension(300, 300));
    int compIndex = 0;
    for (int j = 0; j < groups2Comps.length; j++) {
        String[] nextGroup = groups2Comps[j];
        JPanel groupPane = new JPanel();
        groupPane.setLayout(new BoxLayout(groupPane, BoxLayout.Y_AXIS));
        groupPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(nextGroup[0]),
                BorderFactory.createEmptyBorder(1, 1, 1, 1)));
        for (int i = 1; i < nextGroup.length; i++) {
            JButton configButton = new JButton();
            Icon configIcon = new ImageIcon(DatabaseImportMain.class.getResource("configure.png"), "Configure");
            configButton.setIcon(configIcon);
            configButton.setPreferredSize(new Dimension(configIcon.getIconWidth(), configIcon.getIconHeight()));
            configButton.addActionListener(new ConfigButtonActionListener(nextGroup[i]));
            configButton.setBorderPainted(false);
            //System.out.println("Adding checkbox for "+components[i].getClass().getName());
            checkboxes[compIndex] = new JCheckBox(nextGroup[i]);
            checkboxes[compIndex].setFocusable(true);
            //checkboxes[i].setPreferredSize(new Dimension(200, 30));
            JPanel line = new JPanel();
            line.setLayout(new BorderLayout(5, 0));
            line.add(configButton, BorderLayout.WEST);
            line.add(checkboxes[compIndex], BorderLayout.CENTER);
            groupPane.add(line);/*www  .ja v a 2 s.c  o m*/
            compIndex++;
        }
        checkboxPane.add(groupPane);
    }
    gridC.gridx = 0;
    gridC.gridy = 0;
    gridC.fill = GridBagConstraints.BOTH;
    JScrollPane scrollPane = new JScrollPane(checkboxPane);
    scrollPane.setPreferredSize(new Dimension(450, 300));
    gridBagLayout.setConstraints(scrollPane, gridC);
    getContentPane().add(scrollPane);

    JButton helpButton = new JButton("Help");
    helpButton.setMnemonic(KeyEvent.VK_H);
    helpButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            displayHelpGUI();
        }
    });
    JButton settingsButton = new JButton("Settings");
    settingsButton.setMnemonic(KeyEvent.VK_S);
    settingsButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            currentComponent = "Global properties";
            displaySettingsGUI();
        }
    });
    runButton = new JButton("Run");
    runButton.setMnemonic(KeyEvent.VK_R);
    runButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            runSelectedComponents();
        }
    });

    JButton quitAndSaveButton = new JButton("Quit");
    quitAndSaveButton.setMnemonic(KeyEvent.VK_Q);
    quitAndSaveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                askIfSave();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            System.exit(0);
        }
    });

    gridC.gridy = 1;
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    //buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS));
    //runButton.setAlignmentX(JButton.LEFT_ALIGNMENT);
    buttonPanel.add(runButton);
    //helpButton.setAlignmentX(JButton.LEFT_ALIGNMENT);
    buttonPanel.add(helpButton);
    //settingsButton.setAlignmentX(JButton.LEFT_ALIGNMENT);
    buttonPanel.add(settingsButton);
    //buttonPanel.add(Box.createHorizontalGlue());
    //quitAndSaveButton.setAlignmentX(JButton.RIGHT_ALIGNMENT);
    buttonPanel.add(quitAndSaveButton);
    gridBagLayout.setConstraints(buttonPanel, gridC);
    getContentPane().add(buttonPanel);

    //getContentPane().setPreferredSize(new Dimension(300, 300));
    // End program when closing window:
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            try {
                askIfSave();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            System.exit(0);
        }
    });
}

From source file:com.sshtools.appframework.ui.IconStore.java

private Icon get(String name, int size, String cacheKey, FileObject file)
        throws FileSystemException, IOException {
    Icon icon;
    if (file.getName().getBaseName().toLowerCase().endsWith(".svg")) {
        InputStream in = file.getContent().getInputStream();
        try {/*from   w w w.j  a  v  a2  s.c  om*/
            icon = new SVGIcon(name + "-" + size, in, size, size);
        } finally {
            in.close();
        }
    } else {
        DataInputStream din = new DataInputStream(file.getContent().getInputStream());
        try {
            byte[] imgData = new byte[(int) file.getContent().getSize()];
            din.readFully(imgData);
            icon = new ImageIcon(imgData);
        } finally {
            din.close();
        }
    }
    if (icon.getIconWidth() != size && icon instanceof ImageIcon) {
        Image img = ((ImageIcon) icon).getImage();
        img = img.getScaledInstance(size, size, Image.SCALE_SMOOTH);
        icon = new ImageIcon(img);
    }
    cache.put(cacheKey, icon);
    return icon;
}

From source file:gdt.jgui.entity.webset.JWeblinkEditor.java

/**
 * Get the context locator.//from w w  w  .  ja va  2 s  . c  o  m
 * @return the context locator.
 */
@Override
public String getLocator() {
    try {
        Properties locator = new Properties();
        locator.setProperty(BaseHandler.HANDLER_CLASS, getClass().getName());
        locator.setProperty(BaseHandler.HANDLER_SCOPE, JConsoleHandler.CONSOLE_SCOPE);
        locator.setProperty(JContext.CONTEXT_TYPE, getType());
        locator.setProperty(Locator.LOCATOR_TITLE, getTitle());
        if (entityLabel$ != null) {
            locator.setProperty(EntityHandler.ENTITY_LABEL, entityLabel$);
        }
        if (entityKey$ != null)
            locator.setProperty(EntityHandler.ENTITY_KEY, entityKey$);
        if (entihome$ != null)
            locator.setProperty(Entigrator.ENTIHOME, entihome$);
        if (webLinkKey$ != null)
            locator.setProperty(JWeblinksPanel.WEB_LINK_KEY, webLinkKey$);
        String icon$ = null;
        try {
            Icon icon = iconIcon.getIcon();
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage out = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), type);
            Graphics2D g2 = out.createGraphics();
            icon.paintIcon(new JPanel(), out.getGraphics(), 0, 0);
            g2.dispose();
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            ImageIO.write(out, "png", b);
            b.close();
            byte[] ba = b.toByteArray();
            icon$ = Base64.encodeBase64String(ba);
        } catch (Exception ee) {
        }
        if (icon$ == null)
            icon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "edit.png");
        locator.setProperty(Locator.LOCATOR_ICON, icon$);
        return Locator.toString(locator);
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
        return null;
    }

}

From source file:com.sshtools.appframework.ui.SshToolsApplication.java

public void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
    if (laf != null) {
        log.info("Setting Look and Feel to " + laf.getClassName());
        try {//from  w w  w  .  j a v  a2  s  .  co m
            @SuppressWarnings("unchecked")
            LookAndFeel l = createLookAndFeel((Class<LookAndFeel>) Class.forName(laf.getClassName()));
            UIManager.setLookAndFeel(l);

            Icon checkIcon = UIManager.getIcon("CheckBoxMenuItem.checkIcon");
            Icon radioIcon = UIManager.getIcon("RadioButtonMenuItem.checkIcon");
            UIManager.put("MenuItem.checkIcon", new EmptyIcon(
                    Math.max(checkIcon.getIconWidth(), radioIcon.getIconWidth()), checkIcon.getIconHeight()));
            UIManager.put("Menu.checkIcon", new EmptyIcon(
                    Math.max(checkIcon.getIconWidth(), radioIcon.getIconWidth()), checkIcon.getIconHeight()));

            for (SshToolsApplicationContainer container : containers) {
                container.updateUI();
            }
            for (OptionsTab tab : additionalOptionsTabs) {
                SwingUtilities.updateComponentTreeUI(tab.getTabComponent());
            }

        } catch (Throwable t) {
            /* DEBUG */t.printStackTrace();
        }
    }
}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java

private void addToolbar() {
    final JToolBar toolbar = new JToolBar();

    final Icon addIcon = Utils.icon("add16.png");

    final JButton addButton = new JButton(addIcon);
    addButton.addActionListener(new ActionListener() {
        @Override/*from   w  ww. jav a 2 s  .  c  o m*/
        public void actionPerformed(final ActionEvent e) {
            startAddServerWizard();
        }
    });
    addButton.setBounds(10, 10, addIcon.getIconWidth(), addIcon.getIconHeight());

    final Icon refreshIcon = Utils.icon("refresh16.png");
    final JButton refreshButton = new JButton(refreshIcon);
    refreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            refreshSelectedServers();
        }
    });
    refreshButton.setBounds(10, 10, refreshIcon.getIconWidth(), refreshIcon.getIconHeight());

    final Icon searchIcon = Utils.icon("search16.png");
    final JButton searchButton = new JButton(searchIcon);
    searchButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showFilter();
        }
    });
    searchButton.setBounds(10, 10, searchIcon.getIconWidth(), searchIcon.getIconHeight());

    toolbar.add(addButton);
    toolbar.add(refreshButton);
    toolbar.add(searchButton);
    toolbar.setFloatable(false);
    add(toolbar, BorderLayout.PAGE_START);
}

From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java

/**
 * Paint <code>v</code>'s icon on <code>g</code> at <code>(x,y)</code>.
 *//*from   www  .ja v a 2 s. c  o  m*/
public void paintIconForVertex(Graphics g, Vertex v, int x, int y) {
    Icon icon = vertexIconFunction.getIcon(v);
    if (icon == null) {
        Shape s = AffineTransform.getTranslateInstance(x, y)
                .createTransformedShape(getVertexShapeFunction().getShape(v));
        paintShapeForVertex((Graphics2D) g, v, s);
    } else {
        int xLoc = x - icon.getIconWidth() / 2;
        int yLoc = y - icon.getIconHeight() / 2;
        icon.paintIcon(screenDevice, g, xLoc, yLoc);
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Notification that the Map was received.
 * @param map icon of the map that was generated
 *//*from  w w w .j a  va 2  s .c o  m*/
protected void mapImageReceived(final Icon map) {
    JStatusBar statusBar = UIRegistry.getStatusBar();
    statusBar.setProgressDone(WorkbenchTask.WORKBENCH);
    statusBar.setText("");

    if (map != null) {
        UIHelper.positionFrameRelativeToTopFrame(mapFrame);
        mapFrame.setVisible(true);
        mapImageLabel.setIcon(map);
        //showMapBtn.setEnabled(true);

        // is the map really skinny?
        int ht = map.getIconHeight();
        int wd = map.getIconWidth();
        if (ht < 20 && wd > 100 || ht > 100 && wd < 20) {
            statusBar.setWarningMessage("WB_THIN_MAP_WARNING");
        }
    }
}

From source file:ome.formats.importer.gui.CommentMessenger.java

/**
 * @param owner - owner JFrame//from w  w w.  j  av a 2s.c o m
 * @param title - comment dialog title
 * @param config - import config
 * @param modal - modal yes/no
 * @param debug - display debug borders yes/no
 */
CommentMessenger(JFrame owner, String title, ImportConfig config, Boolean modal, boolean debug) {
    super(owner);
    this.config = config;

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setTitle(title);
    setModal(modal);
    setResizable(true);
    setSize(new Dimension(680, 400));
    setLocationRelativeTo(owner);

    // Set up the main panel for tPane, quit, and send buttons
    double mainTable[][] = { { 10, 150, TableLayout.FILL, 100, 5, 100, 10 }, // columns
            { TableLayout.FILL, 40 } }; // rows

    mainPanel = GuiCommonElements.addMainPanel(this, mainTable, 10, 10, 10, 10, debug);

    // Add the quit, cancel and send buttons to the main panel
    //quitBtn = GuiCommonElements.addButton(mainPanel, "Quit Application", 'Q',
    //        "Quit the application", "1, 1, f, c", debug);
    //quitBtn.addActionListener(this);

    cancelBtn = GuiCommonElements.addButton(mainPanel, "Cancel", 'C', "Cancel your message", "3, 1, f, c",
            debug);
    cancelBtn.addActionListener(this);

    sendBtn = GuiCommonElements.addButton(mainPanel, "Send", 'S', "Send your comment to the development team",
            "5, 1, f, c", debug);
    sendBtn.addActionListener(this);

    this.getRootPane().setDefaultButton(sendBtn);
    GuiCommonElements.enterPressesWhenFocused(sendBtn);

    // fill out the comments panel (changes according to icon existance)        
    Icon icon = GuiCommonElements.getImageIcon(ICON);

    int iconSpace = 0;
    if (icon != null)
        iconSpace = icon.getIconWidth() + 20;

    double commentTable[][] = { { iconSpace, (160 - iconSpace), TableLayout.FILL }, // columns
            { 90, 30, TableLayout.FILL } }; // rows

    commentPanel = GuiCommonElements.addMainPanel(this, commentTable, 10, 10, 10, 10, debug);

    message = "Thank you for taking the time to send us your comments. \n\n"
            + "Your feedback will be used to further the developmment of the "
            + "importer and improve our software. Any personal details you provide are"
            + " purely optional, and will only be used for development purposes.";

    JLabel iconLabel = new JLabel(icon);
    commentPanel.add(iconLabel, "0,0, l, c");

    instructions = GuiCommonElements.addTextPane(commentPanel, message, "1,0,2,0", debug);

    emailTextField = GuiCommonElements.addTextField(commentPanel, "Email: ", emailText, 'E',
            "Input tyour email address here.", "(Optional)", TableLayout.PREFERRED, "0, 1, 2, 1", debug);

    emailTextField.setText(config.email.get());

    commentTextArea = GuiCommonElements.addScrollingTextArea(commentPanel, "Comment:", "", 'W', "0, 2, 2, 2",
            debug);

    // Add the tab panel to the main panel
    mainPanel.add(commentPanel, "0, 0, 6, 0");

    add(mainPanel, BorderLayout.CENTER);

    setVisible(true);

}

From source file:ome.formats.importer.gui.DebugMessenger.java

/**
 * @param owner - parent JFrame//w  w w.  j a  v  a2s.c o  m
 * @param title - dialog title
 * @param config - importerconfig
 * @param modal - modal yes/no
 * @param errorsArrayList - array of ErrorContainers to be sent.
 */
DebugMessenger(JFrame owner, String title, ImportConfig config, Boolean modal,
        ArrayList<ErrorContainer> errorsArrayList) {
    super(owner);
    this.config = config;
    this.owner = owner;
    this.errorsArrayList = errorsArrayList;

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setTitle(title);
    setModal(modal);
    setResizable(true);
    setSize(new Dimension(680, 400));
    setLocationRelativeTo(owner);

    file_info = "(Calculating file info)";

    // Set up the main panel for tPane, quit, and send buttons
    double mainTable[][] = { { 10, 150, TableLayout.FILL, 100, 5, 150, 5, 150, 10 }, // columns
            { TableLayout.FILL, 20, 40 } }; // rows

    mainPanel = GuiCommonElements.addMainPanel(this, mainTable, 10, 10, 10, 10, debug);

    cancelBtn = GuiCommonElements.addButton(mainPanel, "Cancel", 'C', "Cancel your message", "5, 2, f, c",
            debug);
    cancelBtn.addActionListener(this);

    sendBtn = GuiCommonElements.addButton(mainPanel, "Send Comment", 'S',
            "Send your comment to the development team", "7, 2, f, c", debug);
    sendBtn.addActionListener(this);

    this.getRootPane().setDefaultButton(sendBtn);
    GuiCommonElements.enterPressesWhenFocused(sendBtn);

    uploadCheckmark = GuiCommonElements.addCheckBox(mainPanel,
            "Send the image files for these errors. " + file_info, "1,1,7,1", debug);
    //uploadCheckmark.setSelected(config.sendFiles.get());
    uploadCheckmark.setSelected(true);

    logUploadCheckmark = GuiCommonElements.addCheckBox(mainPanel, "Send importer log file.", "1,2,7,2", debug);
    config.sendLogFile.load();
    uploadCheckmark.setSelected(config.sendLogFile.get());
    //logUploadCheckmark.setSelected(true);

    // fill out the comments panel (changes according to icon existance)        
    Icon icon = GuiCommonElements.getImageIcon(ICON);

    int iconSpace = 0;
    if (icon != null)
        iconSpace = icon.getIconWidth() + 10;

    double commentTable[][] = { { iconSpace, (160 - iconSpace), TableLayout.FILL }, // columns
            { 100, 30, TableLayout.FILL, 110 } }; // rows

    commentPanel = GuiCommonElements.addMainPanel(this, commentTable, 10, 10, 10, 10, debug);

    String message = "To help us improve our software, please fill "
            + "out the following form. \n\nPlease note that providing your email "
            + "address is optional, however doing so will make it easier for us "
            + "to contact you for addition information about your errors, and for "
            + "you to track their status.";

    JLabel iconLabel = new JLabel(icon);
    commentPanel.add(iconLabel, "0,0, l, c");

    instructions = GuiCommonElements.addTextPane(commentPanel, message, "1,0,2,0", debug);

    emailTextField = GuiCommonElements.addTextField(commentPanel, "Email: ", emailText, 'E',
            "Input your email address here.", "(Optional)", TableLayout.PREFERRED, "0, 1, 2, 1", debug);

    emailTextField.setText(config.email.get());

    commentTextArea = GuiCommonElements.addScrollingTextArea(commentPanel,
            "Please provide any additional information of importance.", "", 'W', "0, 2, 2, 3", debug);

    // Add the tab panel to the main panel
    mainPanel.add(commentPanel, "0, 0, 8, 0");

    add(mainPanel, BorderLayout.CENTER);

    setVisible(true);

    checker = new FileSizeChecker(errorsArrayList);
    checker.addObserver(this);
    checker.run();

    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            checker.doStop();
        }
    });

}