Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #1388 > unrolled thread

icon image on JToolBar

Started by"jr" <jr@THRWHITE.remove-dii-this>
First post2011-04-27 15:33 +0000
Last post2011-04-27 15:33 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.lang.java.gui


Contents

  icon image on JToolBar "jr" <jr@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000
    Re: icon image on JToolBa "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000
    Re: icon image on JToolBa "Ed Tidwell" <ed.tidwell@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000

#1388 — icon image on JToolBar

From"jr" <jr@THRWHITE.remove-dii-this>
Date2011-04-27 15:33 +0000
Subjecticon image on JToolBar
Message-ID<1175703258.865849.254000@e65g2000hsc.googlegroups.com>
  To: comp.lang.java.gui
Hi, I'm working on an application that uses a toolbar. I have written
the code below. My problem is that the icons that I'm using are of
different sizes that's why the the toolbar doesn't look so good. Is
there a way to make the buttons of the same sizes? Thanks..

JToolBar toolBar = new JToolBar("Tool Bar");

JButton insert, delete;

ImageIcon insertB = createImageIcon("images/open.gif");
insert = new JButton(insertB);
toolBar.add(insert);

ImageIcon deleteB = createImageIcon("images/delete.gif");
delete = new JButton(deleteB);
toolBar.add(delete);


protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = SSFriend.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        }
        else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#1390 — Re: icon image on JToolBa

From"Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this>
Date2011-04-27 15:33 +0000
SubjectRe: icon image on JToolBa
Message-ID<1175712583.866580.122560@p77g2000hsh.googlegroups.com>
In reply to#1388
  To: comp.lang.java.gui
On Apr 4, 9:14 am, "jr" <ramirez.j...@gmail.com> wrote:
> Hi, I'm working on an application that uses a toolbar. I have written
> the code below. My problem is that the icons that I'm using are of
> different sizes that's why the the toolbar doesn't look so good. Is
> there a way to make the buttons of the same sizes? Thanks..
>
> JToolBar toolBar = new JToolBar("Tool Bar");
>
> JButton insert, delete;
>
> ImageIcon insertB = createImageIcon("images/open.gif");
> insert = new JButton(insertB);
> toolBar.add(insert);
>
> ImageIcon deleteB = createImageIcon("images/delete.gif");
> delete = new JButton(deleteB);
> toolBar.add(delete);
>
> protected static ImageIcon createImageIcon(String path) {
>         java.net.URL imgURL = SSFriend.class.getResource(path);
>         if (imgURL != null) {
>             return new ImageIcon(imgURL);
>         }
>         else {
>             System.err.println("Couldn't find file: " + path);
>             return null;
>         }
>     }

Yes, its called Photoshop.
If you want to resize them in the program, be ready for poor looking
icons.  You could load the Image objects yourself, and scale them to
the same size. (ugh)

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#1427 — Re: icon image on JToolBa

From"Ed Tidwell" <ed.tidwell@THRWHITE.remove-dii-this>
Date2011-04-27 15:33 +0000
SubjectRe: icon image on JToolBa
Message-ID<461bdc17$0$17189$4c368faf@roadrunner.com>
In reply to#1388
  To: comp.lang.java.gui
jr wrote:
> Hi, I'm working on an application that uses a toolbar. I have written
> the code below. My problem is that the icons that I'm using are of
> different sizes that's why the the toolbar doesn't look so good. Is
> there a way to make the buttons of the same sizes? Thanks..
> 
Here is a good link even though it is rather dated:
http://java.sun.com/products/jlf/ed2/guidelines.html

If you look at the resources here you will find a set of icons.
Any icons for use in GUI application will have a standard look&feel with 
fixed sizes.  Using the same sized images will ensure your buttons are 
the same size.

The preferred way to really do this is by creating an action and then 
binding it to several JComponents.

This is an abstract class I leverage a lot to do just that...




package net.java.dev.tframe.swing.action;

import javax.swing.*;

import net.java.dev.tframe.swing.*;

/**
  * This class abstract provides an enforced interface for
  * a JButton type of control that can be added to either a JMenu or a 
JToolbar.
  * The advantage is you create it only once and put it in two places.  The
  * other advantage is you can disable the control ONLY once and it is 
disabled
  * in both places at the same time.
  */
public abstract class TAbstractAction extends AbstractAction {
   protected TFrame _frame; // main JFrame of the framework

   public TAbstractAction(final TActionInfo actionInfo) {
     // set reference to main JFrame
     _frame = actionInfo._frame;
     putValue(DEFAULT, actionInfo._caption);
     putValue(NAME, actionInfo._caption);
     putValue(SHORT_DESCRIPTION, actionInfo._tooltip);
     putValue(LONG_DESCRIPTION, actionInfo._statusBar);

     if (actionInfo._image != null) {
       putValue(SMALL_ICON, actionInfo._image);

     }
     if (actionInfo._mnemonic != 0) {
       putValue(MNEMONIC_KEY, new Integer(actionInfo._mnemonic));
     }
     if (actionInfo._hotKey != null) {
       putValue(ACCELERATOR_KEY, actionInfo._hotKey);
     }
   }

   public abstract void actionPerformed(java.awt.event.ActionEvent event);
}

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web