Using NetBeans 7.3.1 i have created a JFrame. A JLabel fills the bottom of the JFrame . The JLabel displays an ImageIcon. I want the ImageIcon automatically resize itself when JLabel resizes. Generated Code from IDE : jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Number_theory/resources/primes_ulam_spiral.gif"))); // NOI18N jLabel1.setDoubleBuffered(true); jLabel1.setOpaque(true); jLabel1.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { jLabel1ComponentResized(evt); } }); My way to change Icon's dimensions according to label's dimensions. private void jLabel1ComponentResized(java.awt.event.ComponentEvent evt) { int labelwidth = jLabel1.getWidth(); int labelheight = jLabel1.getHeight(); ImageIcon Icon = new javax.swing.ImageIcon(getClass().getResource("/Number_theory/resources/primes_ulam_spiral.gif")); Image img = Icon.getImage(); jLabel1.setIcon( new ImageIcon(img.getScaledInstance(labelwidth,labelheight ,Image.SCALE_FAST))); } The result is a slow adjustment to frame …

Member Avatar
Member Avatar
+0 forum 1

My goal is to create a clone of minesweeper. I've created a custon component that extends the JButton class, for each of the minesweeper buttons. I've called this new class SweeperButton. the game board is going to be made in another class by creating a two deminsional array of SweeperButtons, displaying them, and handling the logic for the game. That having been said, there's somewhere between 12 and 15 images that I need to load into the program as ImageIcons, so that my SweeperButtons can use them as icons. although I'd like the array of images to be loaded into …

Member Avatar
+0 forum 0

My application has a lot of buttons on it, and in order to create a skin for my application, I've been just creating a lot of images in my working directory and loading them all into my application as ImageIcons. I like working with ImageIcons, but not working with a lot of images in my working directory, so does anyone know how to take one bitmap image and seperate it into multiple ImageIcons? ultimately what I'd like to do is push all my images together into one image and then just say the first ImageIcon is this portion of the …

Member Avatar
Member Avatar
+0 forum 2

import javax.swing.JPanel; import javax.swing.ImageIcon; import java.awt.Image; import java.awt.Graphics; import java.awt.Graphics2D; class View extends JPanel { Image icon1,icon2; public View(){ ImageIcon i1=new ImageIcon(this.getClass().getResource("tile1.png"));//image I drew ImageIcon i2=new ImageIcon(this.getClass().getResource("tile2.png"));//image I downloaded icon1=i1.getImage(); icon2=i2.getImage(); } public void paint(Graphics g){ super.paint(g); Graphics2D g2=(Graphics2D)g; g2.drawImage(icon1,10,10,null);//this image is not displayed g2.drawImage(icon2,200,200,null);//this image is displayed } } In the above code, I'm simply trying to load some images and display it in the window. Now, I drew an image using MSPaint and saved it in bmp/png (icon1). And I downloaded another image off the internet in gif/png (icon2). The images are present in the same directory as …

Member Avatar
Member Avatar
+0 forum 5

I have a project, it's simple game just to make a game called congklak. it is traditioanl game from Indonesia. The project has finished, and work, well compiled, all components like package, database (*.mdb), and all the pictures are read by programs. But when it's deployed, the pictures and database cannot detected by the programs. All the picture are link in ImageIcon class with valid path, and the database using JDBC. I deploy it with Eclipse Indigo. The project is deployed but not well-deployed because pictures and database are not detected. Help me please, i'm new in java

Member Avatar
Member Avatar
+0 forum 1

The following code works: [CODE] public class Main { public static void main (String args[]){ final JWindow f = new JWindow(); JLabel l = new JLabel(new ImageIcon(Main.class.getResource("images/logo.png"))); f.getContentPane().add(l, BorderLayout.CENTER); f.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension labelSize = l.getPreferredSize(); f.setLocation(screenSize.width/2 - (labelSize.width/2), screenSize.height/2 - (labelSize.height/2)); f.setVisible(true); f.setAlwaysOnTop(true); } }[/CODE] When I use exactly the same code in a different class (public class appForm extends javax.swing.JFrame) the screen that pops up is blank, however it does have the dimensions of the loaded image. If I try to load a different image, the dimensions of the JWindow always correspond to the dimensions of …

Member Avatar
Member Avatar
+0 forum 10

The End.