javax.swing.ImageIcon Java Examples

The following examples show how to use javax.swing.ImageIcon. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageDetailProvider.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
ImageTopComponent(Image image, String className, int instanceNumber) {
    setName(BrowserUtils.getSimpleType(className) + "#" + instanceNumber);
    setToolTipText("Preview of " + className + "#" + instanceNumber);
    setLayout(new BorderLayout());

    int width = image.getWidth(null);
    int height = image.getHeight(null);
    BufferedImage displayedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = displayedImage.createGraphics();
    drawChecker(g, 0, 0, width, height);
    g.drawImage(image, 0, 0, null);

    JComponent c = new JScrollPane(new JLabel(new ImageIcon(displayedImage)));
    add(c, BorderLayout.CENTER);


    JToolBar toolBar = new JToolBar();
    toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); //NOI18N
    toolBar.setFloatable(false);
    toolBar.setName(Bundle.ImageDetailProvider_Toolbar());

    //JButton button = new JButton();
    //button.setText("");
    toolBar.add(new ImageExportAction(image));
    add(toolBar, BorderLayout.NORTH);
}
 
Example #2
Source File: VersionInfoForm.java    From magarena with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Helper method to load an image file from the CLASSPATH
 * @param imageName the package and name of the file to load relative to the CLASSPATH
 * @return an ImageIcon instance with the specified image file
 * @throws IllegalArgumentException if the image resource cannot be loaded.
 */
public ImageIcon loadImage( String imageName )
{
   try
   {
      ClassLoader classloader = getClass().getClassLoader();
      java.net.URL url = classloader.getResource( imageName );
      if ( url != null )
      {
         ImageIcon icon = new ImageIcon( url );
         return icon;
      }
   }
   catch( Exception e )
   {
      e.printStackTrace();
   }
   throw new IllegalArgumentException( "Unable to load image: " + imageName );
}
 
Example #3
Source File: CustomCheckBoxEditor.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
/**
 * Use null for default Images
 * 
 * @param checkedImg Image that should be displayed if checked
 * @param uncheckedImg Image that should be displayed if not checked
 */
public CustomCheckBoxEditor(String uncheckedImg, String checkedImg) {
    super(new JCheckBox());
    setClickCountToStart(0);
    
    editorComponent = (JCheckBox) super.editorComponent;
    editorComponent.setHorizontalAlignment(SwingConstants.CENTER);
    editorComponent.setText("");
    
    try {
        unchecked = new ImageIcon(this.getClass().getResource(uncheckedImg));
        checked = new ImageIcon(this.getClass().getResource(checkedImg));
    } catch (Exception e) {
        unchecked = null;
        checked = null;
    }
}
 
Example #4
Source File: MessageWindow.java    From javagame with MIT License 6 votes vote down vote up
public MessageWindow(Rectangle rect) {
    this.rect = rect;

    innerRect = new Rectangle(
            rect.x + EDGE_WIDTH,
            rect.y + EDGE_WIDTH,
            rect.width - EDGE_WIDTH * 2,
            rect.height - EDGE_WIDTH * 2);

    textRect = new Rectangle(
            innerRect.x + 16,
            innerRect.y + 16,
            320,
            120);
    
    // ���b�Z�[�W�G���W�����쐬
    messageEngine = new MessageEngine();

    // �J�[�\���C���[�W�����[�h
    ImageIcon icon = new ImageIcon(getClass().getResource("image/cursor.gif"));
    cursorImage = icon.getImage();
    
    timer = new Timer();
}
 
Example #5
Source File: WeightVisualiser.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
private void displayWeight(List<Double> currentKernel) {

		JFrame frame = new JFrame("Weight Visualiser: ");
		frame.setSize(400, 400);

		JLabel label = new JLabel();
		Dimension d = new Dimension(kernel.getWidth() * RATIO, kernel.getHeight() * RATIO);
		label.setSize(d);
		label.setPreferredSize(d);

		frame.getContentPane().add(label, BorderLayout.CENTER);
		frame.pack();
		frame.setVisible(true);

		BufferedImage image = new BufferedImage(kernel.getWidth(), kernel.getHeight(), BufferedImage.TYPE_BYTE_GRAY);

		int[] rgb = convertWeightToRGB(currentKernel);
		image.setRGB(0, 0, kernel.getWidth(), kernel.getHeight(), rgb, 0, kernel.getWidth());
		label.setIcon(new ImageIcon(image.getScaledInstance(kernel.getWidth() * RATIO, kernel.getHeight() * RATIO, Image.SCALE_SMOOTH)));

	}
 
Example #6
Source File: ConnectionPanel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Defines an <code>Action</code> object with a default description string and default icon.
 *
 * @param dataSourceList the list containing the datasources
 */
private RemoveDataSourceAction(final JList dataSourceList)
{
  this.dataSourceList = dataSourceList;
  setEnabled(getDialogModel().isConnectionSelected());
  final URL resource = ConnectionPanel.class.getResource("/org/pentaho/reporting/ui/datasources/jdbc/resources/Remove.png");
  if (resource != null)
  {
    putValue(Action.SMALL_ICON, new ImageIcon(resource));
  }
  else
  {
    putValue(Action.NAME, bundleSupport.getString("ConnectionPanel.Remove.Name"));
  }
  putValue(Action.SHORT_DESCRIPTION, bundleSupport.getString("ConnectionPanel.Remove.Description"));
}
 
Example #7
Source File: PlayerChooser.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(
    final JList<?> list,
    final Object value,
    final int index,
    final boolean isSelected,
    final boolean cellHasFocus) {
  super.getListCellRendererComponent(
      list, ((GamePlayer) value).getName(), index, isSelected, cellHasFocus);
  if (uiContext == null || value == GamePlayer.NULL_PLAYERID) {
    setIcon(new ImageIcon(Util.newImage(32, 32, true)));
  } else {
    setIcon(new ImageIcon(uiContext.getFlagImageFactory().getFlag((GamePlayer) value)));
  }
  return this;
}
 
Example #8
Source File: EditableDisplayerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Samples a trivial number of pixels from an image and compares them with
 *pixels from a component to determine if the image is painted on the
 * component at the exact position specified */
private void assertImageMatch(String msg, Image i, JComponent comp, int xpos, int ypos) throws Exception {
    ImageIcon ic = new ImageIcon(i);
    int width = ic.getIconWidth();
    int height = ic.getIconHeight();
    
    for (int x=2; x < 5; x++) {
        for (int y=2; y < 5; y++) {
            int posX = width / x;
            int posY = height / y;
            System.err.println("  Check " + posX + "," + posY);
            assertPixelFromImage(msg, i, comp, posX, posY, xpos + posX, ypos + posY);
        }
    }
    
}
 
Example #9
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addShowAxesButton(JToolBar buttonBar, Insets margin) {
	xyzAxis = new JToggleButton( new ImageIcon(
			GUIFrame.class.getResource("/resources/images/Axes-16.png")) );
	xyzAxis.setMargin(margin);
	xyzAxis.setFocusPainted(false);
	xyzAxis.setRequestFocusEnabled(false);
	xyzAxis.setToolTipText(formatToolTip("Show Axes",
			"Shows the unit vectors for the x, y, and z axes."));
	xyzAxis.addActionListener( new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			DisplayEntity ent = (DisplayEntity) sim.getNamedEntity("XYZ-Axis");
			if (ent != null) {
				KeywordIndex kw = InputAgent.formatBoolean("Show", xyzAxis.isSelected());
				InputAgent.storeAndExecute(new KeywordCommand(ent, kw));
			}
			controlStartResume.requestFocusInWindow();
		}
	} );
	buttonBar.add( xyzAxis );
}
 
Example #10
Source File: RecentFiles.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Icon findIconForPath(String path) {
    FileObject fo = RecentFiles.convertPath2File(path);
    final Icon i;
    if (fo == null) {
        i = null;
    } else {
        DataObject dObj;
        try {
            dObj = DataObject.find(fo);
        } catch (DataObjectNotFoundException e) {
            dObj = null;
        }
        i = dObj == null
                ? null
                : new ImageIcon(dObj.getNodeDelegate().getIcon(
                BeanInfo.ICON_COLOR_16x16));
    }
    return i;
}
 
Example #11
Source File: SaveModelAsAction.java    From openAGV with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param manager The gui manager
 */
public SaveModelAsAction(final GuiManager manager) {
  this.guiManager = manager;

  putValue(NAME, BUNDLE.getString("saveModelAsAction.name"));
  putValue(SHORT_DESCRIPTION, BUNDLE.getString("saveModelAsAction.shortDescription"));
  putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("shift ctrl S"));
  putValue(MNEMONIC_KEY, Integer.valueOf('A'));

  ImageIcon icon = ImageDirectory.getImageIcon("/menu/document-save-as.png");
  putValue(SMALL_ICON, icon);
  putValue(LARGE_ICON_KEY, icon);
}
 
Example #12
Source File: BadgeIcon.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean checkDimensions(Image image) {
    ImageIcon imageIcon = new ImageIcon(image);
    if (imageIcon.getIconWidth() != 8) {
        throw new IllegalArgumentException("The width of image must be 8 px");
    }
    if (imageIcon.getIconHeight() != 8) {
        throw new IllegalArgumentException("The height of image must be 8 px");
    }
    return true;
}
 
Example #13
Source File: ControlWindow.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
CloseIcon() {
	img = frame.getGraphicsConfiguration().createCompatibleImage(20, 16, Transparency.TRANSLUCENT);
	Graphics2D g = img.createGraphics();
	g.setColor(Color.black);
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  RenderingHints.VALUE_ANTIALIAS_ON);
	g.drawOval(4 + 2, 2, 12, 12);
	g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
	g.drawLine(4 + 4, 4, 4 + 11, 12);
	g.drawLine(4 + 4, 12, 4 + 11, 4);
	icon = new ImageIcon(img);
}
 
Example #14
Source File: Teleport.java    From javagame with MIT License 5 votes vote down vote up
public Teleport() {
    x = y = 0;
    counter = 0;
    isInTeleport = false;

    // �Z䊐��̃C���[�W��ǂݍ���
    ImageIcon icon = new ImageIcon(getClass().getResource("hexagram.gif"));
    hexagramImage = icon.getImage();
}
 
Example #15
Source File: SoundRecorderTest.java    From PolyGlot with MIT License 5 votes vote down vote up
@Test
public void testSoundRecordingSuite() {
    Assumptions.assumeFalse(GraphicsEnvironment.isHeadless());
    
    System.out.println("SoundRecorderTest.testSoundRecordingSuite");
    
    ImageIcon playButtonUp = PGTUtil.getButtonSizeIcon(new ImageIcon(getClass().getResource(PGTUtil.PLAY_BUTTON_UP)));
    ImageIcon playButtonDown = PGTUtil.getButtonSizeIcon(new ImageIcon(getClass().getResource(PGTUtil.PLAY_BUTTON_DOWN)));
    ImageIcon recordButtonUp = PGTUtil.getButtonSizeIcon(new ImageIcon(getClass().getResource(PGTUtil.RECORD_BUTTON_UP)));
    ImageIcon recordButtonDown = PGTUtil.getButtonSizeIcon(new ImageIcon(getClass().getResource(PGTUtil.RECORD_BUTTON_DOWN)));
    
    try {
        SoundRecorder recorder = new SoundRecorder(null);
        recorder.setButtons(new JButton(), new JButton(), playButtonUp, playButtonDown, recordButtonUp, recordButtonDown);
        recorder.setTimer(new JTextField());
        recorder.setSlider(new JSlider());
        recorder.beginRecording();
        Thread.sleep(1000);
        recorder.endRecording();
        byte[] sound = recorder.getSound();
        recorder.setSound(sound);
        recorder.playPause();
        assertTrue(recorder.isPlaying());
    } catch (Exception e) {
        fail(e);
    } 
}
 
Example #16
Source File: DebugUtils.java    From GIFKR with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void displayImage(Image img) {
	JFrame f = new JFrame("DEBUG IMG");
	
	JLabel label = new JLabel(new ImageIcon(img));
	label.setBorder(BorderFactory.createLineBorder(Color.RED));
	f.setLayout(new BorderLayout());
	f.add(label, BorderLayout.WEST);
	f.pack();
	f.setVisible(true);
	f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
 
Example #17
Source File: BaseDialog.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new BaseDialog.
 * @param owner the Dialog from which the dialog is displayed
 * @param title title of the dialog
 * @param icon  optional icon of the dialog
 */
public BaseDialog( final Dialog owner, final Holder< String > title, final ImageIcon icon ) {
	super( owner, title.value );
	
	parent = owner;
	
	completeInit( icon );
}
 
Example #18
Source File: CBreakpointToolbar.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new button and adds it to the toolbar.
 *
 * @param action The action object to execute when the button is clicked.
 * @param defaultIconPath Path to the icon that is shown on the button.
 * @param rolloverIconPath Path to the rollover icon of the button.
 * @param pressedIconPath Path to the icon that is shown when the button is pressed.
 *
 * @return The created button.
 */
private JButton createAndAddButtonToToolbar(final AbstractAction action,
    final String defaultIconPath, final String rolloverIconPath, final String pressedIconPath) {
  final JButton button = add(CActionProxy.proxy(action));
  button.setBorder(new EmptyBorder(0, 0, 0, 0));

  button.setIcon(new ImageIcon(CMain.class.getResource(defaultIconPath)));
  button.setRolloverIcon(new ImageIcon(CMain.class.getResource(rolloverIconPath)));
  button.setPressedIcon(new ImageIcon(CMain.class.getResource(pressedIconPath)));

  return button;
}
 
Example #19
Source File: Demo.java    From Swing9patch with Apache License 2.0 5 votes vote down vote up
private void initGUI()
{
	// init components
	txtPhotoframeDialogWidth = new JTextField();
	txtPhotoframeDialogHeight = new JTextField();
	txtPhotoframeDialogWidth.setText("530");
	txtPhotoframeDialogHeight.setText("450");
	txtPhotoframeDialogWidth.setColumns(10);
	txtPhotoframeDialogHeight.setColumns(10);
	
	btnShowInFrame = new JButton("Show in new frame...");
	btnShowInFrame.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.blue));
	btnShowInFrame.setForeground(Color.white);
	btnHideTheFrame = new JButton("Hide the frame");
	btnHideTheFrame.setEnabled(false);
	
	panePhotoframe = createPhotoframe();
	panePhotoframe.add(
			new JLabel(new ImageIcon(org.jb2011.swing9patch.photoframe.Demo.class.getResource("imgs/girl.png")))
			, BorderLayout.CENTER);
	
	// init layout
	JPanel paneBtn = new JPanel(new FlowLayout(FlowLayout.CENTER));
	paneBtn.setBorder(BorderFactory.createEmptyBorder(12,0,0,0));
	paneBtn.add(new JLabel("Frame width:"));
	paneBtn.add(txtPhotoframeDialogWidth);
	paneBtn.add(new JLabel("Frame height:"));
	paneBtn.add(txtPhotoframeDialogHeight);
	paneBtn.add(btnShowInFrame);
	paneBtn.add(btnHideTheFrame);
	
	this.setBorder(BorderFactory.createEmptyBorder(12,20,10,20));
	this.add(panePhotoframe, BorderLayout.CENTER);
	this.add(paneBtn, BorderLayout.SOUTH);
	
	// drag panePhotoframe to move its parent window
	DragToMove.apply(new Component[]{panePhotoframe});
}
 
Example #20
Source File: CLoadPanel.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new action object.
 * 
 * @param module Module whose data is updated from the database data.
 */
public CLoadDatabaseAction(final INaviModule module) {
  super("Load");

  m_module = module;

  putValue(Action.SMALL_ICON,
      new ImageIcon(CMain.class.getResource("data/load_from_database.png")));
}
 
Example #21
Source File: Widgets.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Shows a message with some information and an "OK"-button.
 *
 * @param displayObject Optional object for displaying an icon.
 * @param tmpl The {@code StringTemplate} to display.
 * @return The {@code InformationPanel} that is displayed.
 */
public InformationPanel showInformationPanel(FreeColObject displayObject,
                                             StringTemplate tmpl) {
    ImageIcon icon = null;
    Tile tile = null;
    if (displayObject != null) {
        icon = createObjectImageIcon(displayObject);
        tile = (displayObject instanceof Location)
            ? ((Location)displayObject).getTile()
            : null;
    }
    return showInformationPanel(displayObject, tile, icon, tmpl);
}
 
Example #22
Source File: SparkManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the image to use with most dialogs.
 *
 * @return the image to use with most dialogs.
 */
public static ImageIcon getApplicationImage() {
    ImageIcon mainImage = Default.getImageIcon(Default.FRAME_IMAGE);
    if (mainImage == null) {
        mainImage = SparkRes.getImageIcon(SparkRes.MAIN_IMAGE);
    }
    return mainImage;
}
 
Example #23
Source File: PlayListPanel.java    From aurous-app with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(final JList<?> list,
		final Object value, final int index, final boolean isSelected,
		final boolean cellHasFocus) {
	if (value instanceof File) {

		final File file = (File) value;

		setText(file.getName().replace(".plist", ""));
		setIcon(new ImageIcon(
				PlayListPanel.class.getResource("/resources/music.png")));

		if (isSelected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}
		setEnabled(list.isEnabled());
		setFont(list.getFont());
		setOpaque(true);
		if (file.getName().contains("blank.plist")) {

		}
	}
	return this;
}
 
Example #24
Source File: ExperimentalDataNode.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Icon for the node, same as OpenSimNode
 **/
public Image getIcon(int i) {
    URL imageURL = null;
    try {
        imageURL = Class.forName("org.opensim.view.nodes.OpenSimNode").getResource("/org/opensim/view/nodes/icons/motionsNode.png");
    }  catch (ClassNotFoundException ex) {
       ex.printStackTrace();
    }
    if (imageURL != null) {
        return new ImageIcon(imageURL, "").getImage();
    }  else {
       return null;
    }
}
 
Example #25
Source File: Icons.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the icon of the specified ability group in the specified size.
 * @param abilityGroup ability group whose icon to be returned, can be <code>null</code>
 * @param size         size in which the icon to be returned
 * @return the icon of the specified ability group in the specified size
 */
public static Icon getAbilityGroupIcon( final AbilityGroup abilityGroup, final IconSize size ) {
	if ( abilityGroup == null )
		return IconHandler.NULL.get( size );
	
	IconHandler iconHandler = abilityGroupIcons.get( abilityGroup );
	
	if ( iconHandler == null ) {
		// I omit synchronization: it's a rare case, and even it if happens, there are no consequences
		final URL iconResource = Icons.class.getResource( "sc2/abilitygroups/" + abilityGroup.name() + ".jpg" );
		abilityGroupIcons.put( abilityGroup, iconHandler = new IconHandler( iconResource == null ? null : new ImageIcon( iconResource ) ) );
	}
	
	return iconHandler.get( size );
}
 
Example #26
Source File: JPanelMaps.java    From Course_Generator with GNU General Public License v3.0 5 votes vote down vote up
/** Returns an ImageIcon, or null if the path was invalid. */
protected ImageIcon createImageIcon(String path, String description) {
	java.net.URL imgURL = getClass().getResource(path);
	if (imgURL != null) {
		return new ImageIcon(imgURL, description);
	} else {
		System.err.println("CreateImageIcon : Couldn't find file: " + path);
		return null;
	}
}
 
Example #27
Source File: CreateImpliedMatchAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public CreateImpliedMatchAction(VTController controller,
		VTImpliedMatchesTableProvider provider) {
	super("Accept Implied Match", VTPlugin.OWNER);
	this.controller = controller;
	this.provider = provider;

	ImageIcon icon = ResourceManager.loadImage("images/flag.png");
	setToolBarData(new ToolBarData(icon, "1"));
	setPopupMenuData(new MenuData(new String[] { "Accept Implied Match" }, icon, "1"));
	setHelpLocation(new HelpLocation("VersionTrackingPlugin", "Accept_Implied_Match"));
	setEnabled(false);
}
 
Example #28
Source File: DeleteAction.java    From openAGV with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance which acts on the currently focused component.
 */
public DeleteAction() {
  super(ID);

  putValue(NAME, BUNDLE.getString("deleteAction.name"));
  putValue(SHORT_DESCRIPTION, BUNDLE.getString("deleteAction.shortDescription"));
  putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("DEL"));

  ImageIcon image = ImageDirectory.getImageIcon("/menu/edit-delete-2.png");
  putValue(SMALL_ICON, image);
  putValue(LARGE_ICON_KEY, image);
}
 
Example #29
Source File: DisablablModelComponentNode.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
@Override
// return diabled icon if enabled is true else null
public Image getIcon(int i) {
    URL imageURL;
    if (!enabled){
        imageURL = this.getClass().getResource("icons/disabledNode.png");
    
        if (imageURL != null) { 
            return new ImageIcon(imageURL, "Controller").getImage();
        } else {
            return null;
        }
    }
    return null;
}
 
Example #30
Source File: JavaElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public String getIconFile() {
    Object o = getAttributeObject(getComponent(), "icon");
    if (o == null || !(o instanceof Icon)) {
        return null;
    }
    Icon icon = (Icon) o;
    if (icon instanceof ImageIcon) {
        String description = ((ImageIcon) icon).getDescription();
        if (description != null && description.length() != 0) {
            return mapFromImageDescription(description);
        }
    }
    return null;
}