How to resize an image, where extra space is filled with a background color


For example, I want to resize an image with size 3 x 5 pixels, to 10 by 15, keeping the ratio.

To keep the ratio, the result is 9 x 15. There is a 1 pixel area that I want to fill with, say, white color.

Do you have an idea how it is done
Posted On: Wednesday 17th of October 2012 06:34:28 AM Total Views:  132
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




resize icon to fill jLabel surface

I have successfully placed an imageicon onto a jLabel, however, I would like the dynamically changing image to fill the entire jLabel surface. Does anyone know how to manipulate the image to fill the entire jLabel surface The code below shows how I am dynamically updating the image. I created a separate thread to continuously loop and collect a byte array, which is then converted to an imageicon and finally placed on the jLabel. I selected jLabel because it seemed convenient to set the image. As long as the component can have a parent of a jPanel, I do not have an issue with changing the jLabel to another swing component if that component would better fit my needs.
VIEWS ON THIS POST

113

Posted on:

Wednesday 19th September 2012
View Replies!

Unable to resize panel when components are added at runtime to a panel with gridbag layout

I am a fresher to JAVA Swing I am trying an example problem to add components at runtime to a panel. I am able to add the components, but unable to resize the panel. Can someone please suggest me what I am missing here in the following code
VIEWS ON THIS POST

201

Posted on:

Friday 21st September 2012
View Replies!

Cannot get a custom JPanel to resize when the outer panel is resized

I am attempting to insert a JPanel into another JPanel so that when the outer JPanel resizes the inner JPanel will resize itself to match the size of the outer panel. I suppose I could listen for resize events, but I know there's a way to set this up automatically. In fact my outer panel already works this way! My outer panel was positioned onto the JFrame using Netbean's design view, and whenever I resize the frame the outer panel automatically resizes. I considered stealing that code and reusing it for setting up my inner panel, but that auto-generated code is very complicated and uses GroupLayout. The docs don't seem to encourage its use because it states: "GroupLayout is intended for use by builders, but may be hand-coded as well." I figured one of the general layout managers have to provide what I need, but I can't figure this out! The best I've been able to do is to get a panel that will adjust on the horizontal axis but the vertical axis always remains fixed. innerPanel = new MyInnerPanel(); innerPanel.setMinimumSize(new Dimension(0, 0)); innerPanel.setPreferredSize(new Dimension(1280, 800)); innerPanel.setMaximumSize(new Dimension(2000, 2000)); // Add it outerPanel.setLayout( new FlowLayout(FlowLayout.CENTER)); outerPanel.add(innerPanel);
VIEWS ON THIS POST

146

Posted on:

Tuesday 25th September 2012
View Replies!

Cannot see two Jtables until resize

hey , I am running into a problem and i need help, i basically have a jframe with two JPanels which would hold the JScrollpanes of jtables, there are also two JTextFields who would act as a search bar for populating the the Jtable, the programming of data is done correctly but i am running into a problem, the second Jtable does not show until and unless i resize the jframe window, i cant get it to work. I have tried validate(), update(), setvisible() but it wont work, Please i need your help. I have add screenshots for reference and the code i given below:
VIEWS ON THIS POST

94

Posted on:

Friday 28th September 2012
View Replies!

Image.getBounds does not return the actual image position on the screen

I have drawn an image on a Composite using the following code imageCanvas = new Composite(shell, SWT.BORDER); //adding paintListener to the canvas imageCanvas.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { if (sourceImage != null) { // draw the image e.gc.drawImage(sourceImage, 120, 150); //check the bounds of the image using the getBounds function Rectangle newrec = sourceImage.getBounds(); System.out.println("X: " +newrec.x + " Y: "+newrec.y ); // prints (0, 0) instead of (120, 150) } } });
VIEWS ON THIS POST

122

Posted on:

Sunday 30th September 2012
View Replies!

problem in setting background image of jpanel

i m not able to set a background image of my JPanel, can anyone tell me how do i set JPanel Background image\t here is my code, in which i m setting the background color of my JPanel but i want to set an image instead: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Random; class Test { public static void main(String args[]) { JFrame frame = new JFrame(); Cpoint point = new Cpoint(); Cdynamic d = new Cdynamic(point); Cair ca= new Cair(); d.panel.setBackground(Color.ORANGE); point.setBackground(new Color(0,0,255)); JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, d.panel, point); Container c = frame.getContentPane(); c.add(sp, BorderLayout.CENTER); ca.setPreferredSize(new Dimension(200,0)); c.add(ca, BorderLayout.EAST); frame.setVisible(true); frame.setSize(1280,750); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } class Dynamic extends JPanel { JPanel panel; JButton button; JLabel label; Cpoint cp; Dynamic(Cpoint c) { cp = c; System.out.println("Inside Dynamic class"); panel = new JPanel(); panel.setBackground(Color.yellow); button = new JButton("Fish Die"); label = new JLabel("Label to test"); panel.add(button); panel.add(label); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ cp.fishAlive = false; if(cp.timer != null && cp.timer.isRunning()) { cp.timer.stop(); cp.repaint(); } } }); } } class Cpoint extends JPanel implements ActionListener{ Cfish1 ball,ball2,ball3,ball4,ball5,ball6; Cbubble1 bull,bull2,bull3,bull4,bull5,bull6,bull7,bull8,bull9,bull10; int newx, newy, midx,midy,getradius, newwidth, newheight; Timer timer; int count; boolean fishAlive = true; int counter = 0; Cpoint() { timer = new Timer(26, this); timer.start(); ball = new Cfish1(500,100, new ImageIcon("g:\\fish\\fish1.jpg").getImage()); bull = new Cbubble1(20,400); } public void paintComponent(Graphics g) { super.paintComponent(g); if(fishAlive) { ball.DisplayFish(g); bull.DisplayBubble(g); } } public void actionPerformed(ActionEvent e) { ball.movementFish(this); bull.movement_bubble(this); try { repaint(); } catch (Exception ex) { ex.printStackTrace(); } System.out.println("timer "+(counter++)); } } class Cfish1 { int x = 2; int y = 5; int dx = 2; int dy = 1; int radius = 9; Image fishImg; public Cfish1() {} public Cfish1(int x, int y,Image img) { fishImg = img; this.x = x; this.y = y; radius = fishImg.getWidth(null)/2; } public int getRadius() { return radius; } public void movementFish(Cpoint sp) { if(x+dx>sp.getWidth()-radius-4) { x = sp.getWidth()-radius-2; dx = -dx; } else if(x+dxsp.getHeight()-radius-4) { y = sp.getHeight()-radius-4; dy = -dy; } else if(y+dysp.getHeight()-bulradius-4) { buly = sp.getHeight()-bulradius-4; bulradius++; if(bulradius==6) bulradius=1; } else if(buly+buldy
VIEWS ON THIS POST

189

Posted on:

Sunday 30th September 2012
View Replies!

how to give animation to images?

how to give more effects to image, i have a fish image, that is moving around the JFrame, and what i want also animation in fins of fish, how can i do this\t here is my code:- import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Random; class Test { public static void main(String args[]) { JFrame frame = new JFrame(); Cpoint point = new Cpoint(); Cdynamic d = new Cdynamic(point); Cair ca= new Cair(); d.panel.setBackground(Color.ORANGE); point.setBackground(new Color(0,0,255)); JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, d.panel, point); Container c = frame.getContentPane(); c.add(sp, BorderLayout.CENTER); ca.setPreferredSize(new Dimension(200,0)); c.add(ca, BorderLayout.EAST); frame.setVisible(true); frame.setSize(1280,750); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } class Dynamic extends JPanel { JPanel panel; JButton button; JLabel label; Cpoint cp; Dynamic(Cpoint c) { cp = c; System.out.println("Inside Dynamic class"); panel = new JPanel(); panel.setBackground(Color.yellow); button = new JButton("Fish Die"); label = new JLabel("Label to test"); panel.add(button); panel.add(label); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ cp.fishAlive = false; if(cp.timer != null && cp.timer.isRunning()) { cp.timer.stop(); cp.repaint(); } } }); } } class Cpoint extends JPanel implements ActionListener{ Cfish1 ball,ball2,ball3,ball4,ball5,ball6; Cbubble1 bull,bull2,bull3,bull4,bull5,bull6,bull7,bull8,bull9,bull10; int newx, newy, midx,midy,getradius, newwidth, newheight; Timer timer; int count; boolean fishAlive = true; int counter = 0; Cpoint() { timer = new Timer(26, this); timer.start(); ball = new Cfish1(500,100, new ImageIcon("g:\\fish\\fish1.jpg").getImage()); bull = new Cbubble1(20,400); } public void paintComponent(Graphics g) { super.paintComponent(g); if(fishAlive) { ball.DisplayFish(g); bull.DisplayBubble(g); } } public void actionPerformed(ActionEvent e) { ball.movementFish(this); bull.movement_bubble(this); try { repaint(); } catch (Exception ex) { ex.printStackTrace(); } System.out.println("timer "+(counter++)); } } class Cfish1 { int x = 2; int y = 5; int dx = 2; int dy = 1; int radius = 9; Image fishImg; public Cfish1() {} public Cfish1(int x, int y,Image img) { fishImg = img; this.x = x; this.y = y; radius = fishImg.getWidth(null)/2; } public int getRadius() { return radius; } public void movementFish(Cpoint sp) { if(x+dx>sp.getWidth()-radius-4) { x = sp.getWidth()-radius-2; dx = -dx; } else if(x+dxsp.getHeight()-radius-4) { y = sp.getHeight()-radius-4; dy = -dy; } else if(y+dysp.getHeight()-bulradius-4) { buly = sp.getHeight()-bulradius-4; bulradius++; if(bulradius==6) bulradius=1; } else if(buly+buldy
VIEWS ON THIS POST

89

Posted on:

Monday 1st October 2012
View Replies!

MigLayout and auto resize

I have two columns. Actually I would like size1 (size of the first column) to be as little as possible depending of the size of its content (actual content of column 1 : some string...). Of course the size of the second column must change in consequence. Do you know if it's possible Anyway,
VIEWS ON THIS POST

110

Posted on:

Monday 1st October 2012
View Replies!

How can I change a .jpg icon image of an icon for a jLabel using Eclipse IDE?

I had done it successfully using Netbeans in this example: http://www.coderanch.com/t/565811/GUI/java/Newbie-just-trying-change-icon But now, I switched to Eclipse (using the WindowBuilder Pro plugin). It generates a method stub, which I filled with JLabel lblJlabela = null; lblJlabela.setIcon(new ImageIcon("J:\\Eclipse Folder\\Eclipse1GUI\\Photos\\Viper3.jpg")); I had to add the first line of that because it was telling me that lblJlabela was "unresolved"...it auto-suggested that I do that. But here's the whole program. import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class FlashGUI { String[] CarorBike = null; JLabel[] labels; private JFrame frame; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { FlashGUI window = new FlashGUI(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public FlashGUI() { initialize(); JLabel lblJlabela = null, lblJlabelb = null; //labels = new JLabel[]{lblJlabela, lblJlabela, lblJlabelb}; } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 562, 875); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); JLabel lblJlabela = new JLabel("jLabelA"); lblJlabela.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { do_lblJlabela_mousePressed(e); } }); lblJlabela.setIcon(new ImageIcon("J:\\Eclipse Folder\\Eclipse1GUI\\Photos\\Viper1.jpg")); lblJlabela.setBounds(57, 55, 462, 298); frame.getContentPane().add(lblJlabela); JLabel lblJlabelb = new JLabel("jLabelB"); lblJlabelb.setIcon(new ImageIcon("J:\\Eclipse Folder\\Eclipse1GUI\\Photos\\Valkyrie1.jpg")); lblJlabelb.setBounds(42, 438, 448, 300); frame.getContentPane().add(lblJlabelb); } private void do_lblJlabela_mousePressed(MouseEvent e) { JLabel lblJlabela = null; lblJlabela.setIcon(new ImageIcon("J:\\Eclipse Folder\\Eclipse1GUI\\Photos\\Viper3.jpg")); } }
VIEWS ON THIS POST

96

Posted on:

Monday 1st October 2012
View Replies!

All images are showing in Eclipse, only half when exported as Runnable Jar

Hi ! I have a very strange problem. And I can't figure out what could be the problem. I am developing my clone of the old game Frogger, I think that everybody knows the game I'm talking about. Well the main reason to develop Frogger is to learn about java games and 2D graphics, anyway this is my problem. When I run my Frogger application in Eclipse, all the images are shown with no problem with the appropriate animation (Logs moving in one direction car in another), then when I export this project as Runnable Jar and start it, I can see all images, except the car images. I know that the missing car images are moving because when I move my frog on the road it gets killed (returns to the start position.) This is my class that loads and holds the required images. the images are in the same folder (source) public class ImageLoader { private static ImageLoader instance; private Map imagesContext = new HashMap(); private Image image; private Toolkit toolkit; private ImageLoader(){ this.toolkit = Toolkit.getDefaultToolkit(); } public static ImageLoader getInstance(){ if(instance == null){ instance = new ImageLoader(); } return instance; } public Image loadImage(ImagesEnum image){ this.image = this.imagesContext.get(image); if(this.image == null){ this.image = this.toolkit.getImage(this.getImageURL(image)); this.imagesContext.put(image, this.image); } return this.image; } private URL getImageURL(ImagesEnum image){ return this.getClass().getResource("/source/" + ImagesEnum.getImageFilename(image)); } }
VIEWS ON THIS POST

150

Posted on:

Monday 1st October 2012
View Replies!

Displaying generated images greater than 32767 pixels on canvas

Hi I've been stuck on this for almost a week now so here it goes.. The general gist of the application is to generate one large horizontal bar up to approxiamtely 85,000 pixels to model the amount of seconds in a 24hr period, each pixel represents a second. This bar is split into multiple sections, these sections can number sometimes anywhere between 1000-2000, each represent a particular 'event' within the 24hr period. So I might have an event A coloured red and that is 300 seconds, another event Z may be 400 seconds with a yellow bar. So they've taken up 700 horizontal pixels so far --> 700 seconds within the 24hr timespan. These bars and their colours are generated according to a pre-determined 'model' so their never the same. Inititally I tried it with a ScrolledComposite to display the bar, it worked great up till 32767 pixels (the composite expanded to 32767 pixels) of which after I soon found out I reached the maximum pixel limit for composites in Windows and whatever that should have been drawn beyond this point has been cut off, the scrollbars also worked great displaying the 32767 pixels however and with no lag. So after having a consultation with the supervisor I've decided to go for the Canvas approach. The thing is my original approach was with a Canvas but I got stuck hence making me switch to a ScrolledComposite. Now I am back to square one. Here are my questions: 1) Would this be the best approach in your opinion Does canvas support a pixel width of 85,000 (I tried with 'Image' and it failed) My idea was to have a 1000 pixel wide fixed width canvas with scrollbars. Everytime the scrollbars or a 'forward button' is pressed the canvas is repainted to simulate a side "scroll" to show the next lot of pixel graphics. Once the button is clicked on again it shows the next lot of pixel graphics. With this approach I only ever have to deal with 1000 pixels at a time and not the whole 85,000 pixels however I will still be able to view the whole 85,000 pixels without lag or reaching a limit. How would I 'technically' be able to go around doing this Some pointers please! 2) I wrote a "Canvas Test" program to try to test out my idea mentioned above. package canvas; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Event; public class Test { // Test if scrollbars should be added for the canvas or the shell - whichever works better. static int shellStyle = SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND | SWT.CLOSE | SWT.MIN | SWT.RESIZE | SWT.MAX | SWT.H_SCROLL; static int canvasStyle = SWT.NO_REDRAW_RESIZE;// | SWT.H_SCROLL | SWT.V_SCROLL; public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display, shellStyle); shell.setLayout(new FillLayout()); shell.setBackground(display.getSystemColor((SWT.COLOR_CYAN))); shell.setText("Canvas Test"); /** * SWT.NO_BACKGROUND style bit prevents the background of the program to be filled before * the painting of the canvas in the program. * SWT.NO_REDRAW_RESIZE ensures that only the damaged areas of the canvas are repainted when * it is resized as opposed to repainting the whole area. */ final Canvas canvas = new Canvas(shell, canvasStyle); canvas.setLayout(new FillLayout()); canvas.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); final Point origin = new Point(0,0); final ScrollBar hBar = shell.getHorizontalBar(); Rectangle size = canvas.getBounds(); hBar.setMaximum(size.width); hBar.setMinimum(0); // hBar.addListener(SWT.Selection, scrollListener); // vBar.addListener(SWT.Selection, scrollListener); // Create a paint handler for the canvas canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { // Do some drawing e.gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_YELLOW)); e.gc.fillRectangle(100, 200, 100, 200); e.gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN)); e.gc.fillRectangle(900, 200, 600, 200); e.gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_MAGENTA)); e.gc.fillRectangle(500, 200, 300, 200); e.gc.setBackground(display.getSystemColor(SWT.COLOR_GRAY)); e.gc.fillRectangle(1600, 200, 300, 200); } }); // The below event handlers allow for horizontal scrolling functionality hBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { int hSelection = hBar.getSelection(); // Get the current position of the ScrollBar int destX = -hSelection - origin.x; // Store the new position after scrolling Rectangle rect = shell.getBounds(); canvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); origin.x = -hSelection; } }); shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { Rectangle rect = canvas.getBounds(); Rectangle client = shell.getClientArea(); hBar.setMaximum(rect.width); hBar.setThumb(Math.min(rect.width, client.width)); int hPage = rect.width - client.width; int hSelection = hBar.getSelection(); if (hSelection >= hPage) { if (hPage
VIEWS ON THIS POST

112

Posted on:

Monday 1st October 2012
View Replies!

Diagonal resize cursor on Mac Lion

I have an application that resizes a component, I'm able to resize it, however I'm not able to display none of the diagonal resize cursors using (nw, ne, sw, se_resize) this.setCursor(new Cursor(Cursor.NW_RESIZE_CURSOR), I can display any other cursor (wait_cursor, e_resize, n_resize, etc), and it works on machines running linux, windows and mac leopard, so I guess it's a lion issue, is there a workaround for this I tried Cursor.getSystemCustomCursor(String name) but I don't know the names of the cursors.
VIEWS ON THIS POST

69

Posted on:

Monday 1st October 2012
View Replies!

Newbie just trying to change icon image in a Jframe

I used Netbeans drag and drop design interface and it spit out this code: (I know some basic Java, but hardly any Swing or Jframe stuff, although I did read a few chapters from Dietel & Deitel book (actually, many chapters). Seems it should be pretty easy but I am not sure exactly how to go about it. The code it generated has setIcon() as part of a private function...I've looked up repaint and others but the example they gave were not clear to me. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * JavaImageAppUI.java * * Created on Jan 28, 2012, 6:26:33 PM */ package my.javaimageappui; /** * * @author batman */ public class JavaImageAppUI extends javax.swing.JFrame { /** Creates new form JavaImageAppUI */ public JavaImageAppUI() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // private void initComponents() { jLabel1 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setIcon(new javax.swing.ImageIcon("/home/batman/Desktop/Viper-Green.jpg")); // NOI18N jLabel1.setText("jLabel1"); jButton1.setText("Next Image>"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(148, 148, 148) .addComponent(jButton1)) .addGroup(layout.createSequentialGroup() .addGap(62, 62, 62) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(71, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(38, 38, 38) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE) .addComponent(jButton1) .addContainerGap()) ); pack(); }// private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: //This is where I would like to add some code to change the photo } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(JavaImageAppUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(JavaImageAppUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(JavaImageAppUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(JavaImageAppUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new JavaImageAppUI().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; // End of variables declaration }
VIEWS ON THIS POST

84

Posted on:

Tuesday 2nd October 2012
View Replies!

Selection rectangle on image

Hiii... I have a similar problem like this... I created a frame which will have a label to show an image and i am able to display the image. User needs to select some part of the image as rectangle,Here i am able to draw rectangle but it is disappearing when i stop the mouse dragging only.. Here is my code.. Could you please help me what is my mistake and what i need to add As I am new to graphics, can you please give me the code clearly which is need to be added or modified...
VIEWS ON THIS POST

58

Posted on:

Tuesday 16th October 2012
View Replies!

is it possible to retrieve exif data using the javax.imageio package ?

hi, all! I am just wondering if it is possible to retrive by that i refer to read exif data that are part of an image objects header file like camera type and color model and so on Im very much into javas picture handling features theese days and i have wondered about this for a long time but i haven't done that much researching about this topic yet but i know that there is a library for this out there called sanselan if i remembered it correctly If there is a way to retrieve exif data using the imageio package i'd be very much greatful for any tips or hints on how to accieve this. I dont know that much about exif otherwise but i am learning more and more. best regards, krillian.
VIEWS ON THIS POST

91

Posted on:

Wednesday 17th October 2012
View Replies!

Error on seting images to labels: NullPointException

Please have a look at the following code Class mainWindow import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class mainWindow extends JFrame implements ActionListener { JButton open, preview; JFileChooser fileChooser; File selectedFiles[]; String str[]; JLabel label; preview p; int miliSeconds = 1000; public mainWindow() { open = new JButton("Open"); open.addActionListener(this); preview = new JButton("Preview"); preview.addActionListener(this); label = new JLabel(); fileChooser = new JFileChooser(); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); panel.add(open); panel.add(preview); JPanel labelPanel = new JPanel(); labelPanel.setLayout(new FlowLayout()); labelPanel.add(label); JPanel main = (JPanel)getContentPane(); main.setLayout(new BorderLayout()); main.add(panel,"Center"); main.add(labelPanel,"South"); } public void actionPerformed(ActionEvent ae) { if(ae.getSource().equals(open)) { fileChooser.setMultiSelectionEnabled(true); int returnVal = fileChooser.showOpenDialog(mainWindow.this); if(returnVal==JFileChooser.APPROVE_OPTION) { selectedFiles = fileChooser.getSelectedFiles(); str = new String[selectedFiles.length]; for(int i=0;i
VIEWS ON THIS POST

149

Posted on:

Wednesday 17th October 2012
View Replies!

Insert an image into Java program

I know that when i want to create an image icon i can write this for example ImageIcon arrow = new ImageIcon("Path of the image here");
VIEWS ON THIS POST

63

Posted on:

Wednesday 17th October 2012
View Replies!

FrameView only gets repainted when I resize the window

My Java swing GUI doesn't repaint until I resize the window. I create a FrameView with a menuBar (with menu items whose events cause the loading of different JPanels via FrameView's setComponent) and a dummy/empty JPanel. When user selects a menu item, a custom JPanel is created and FrameView's setComponent is called with this as a parameter. When I run it and select the menu item, I don't see the new JPanel being loaded -- until I manually resize the window. Any help Following is the code snippet: public class MyDesktopApp extends SingleFrameApplication { @Override protected void startup() { show(new MyDesktopView(this)); } } public class MyDesktopView extends FrameView { public MyDesktopView (SingleFrameApplication app) { mainPanel = new JPanel(); mainMenu = new JMenu(); importMenu = new JMenu(); menuBar = new JMenuBar(); importMyFileMenuItem = new JMenuItem(); importMyFileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { importMyFileMenuItemActionPerformed(evt); } }); importMenu .add(importMyFileMenuItem ); mainMenu.add(importMenu); menuBar.add(mainMenu); setMenuBar(menuBar); setComponent(mainPanel); } private void importMyFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) { ImportMyFileJPanel importMyFileJPanel = new ImportMyFileJPanel (); setComponent(importMyFileJPanel ); importMyFileJPanel .setVisible(true); } } public class ImportBOIJPanel extends JPanel { public ImportBOIJPanel() { // add swing components } }
VIEWS ON THIS POST

89

Posted on:

Wednesday 17th October 2012
View Replies!

How to insert .gif image inside a panel

I want to insert a .gif image in a panel. I am using following code : java.net.URL imageURL = getClass().getClassLoader().getResource("images/loading.gif"); ImagePanel loading = new ImagePanel(new ImageIcon(imageURL).getImage()); this.jPanel1.add(loading); Using this if I insert normal image it displays but if I changes it to loading.gif it doesn't ... What is the issue and how to fix it
VIEWS ON THIS POST

69

Posted on:

Wednesday 17th October 2012
View Replies!

How to display 256 images in a 16x16 grid

My target is to display 256 images in a 16x16 grid (as the subject of this topic already hints at). This grid should be positioned in a container. When clicking with the mouse on one of the images I want to know on which image the click was made, and that in a way that makes it easy to get the coordinates (0,0 being the top left image, 15,15 the bottom right). I use NetBeans and JSE 6. As a beginner I would like to get a hint to the following preliminary thoughts I had. a. Use labels (JLabel). Problem: You have to generate 256 of them. Not very attractive to do with NetBeans - and you have no elegant way to get the coordinates back (using the name of JLabel - JLabel3x5, JLabel15x15 - seems very awkward , using the graphic coordinates is not reliable if the window is resized). Even if you do not use NetBeans and generate the labels manually, say in an array, the coordinate problem remains. b. Use a table (JTable), display the images in a grid and prevent the cells from being editable. As far as I got it you can define your own TableModel and include something like public boolean isCellEditable(int row, int col) { return false; }
VIEWS ON THIS POST

115

Posted on:

Wednesday 17th October 2012
View Replies!