This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
In my application for image display, those images are displayed which resides in the same folder as my program(code) is.... But now i want to display those images of folder respective to which an user click on a particular folder of local drives on a JTree... I am sending codes which i have written... Please take a view... and please make any necessary changes and reply with the changed codes.
private BufferedImage[] createThumbnails(BufferedImage[] origs) { final int WIDTH = 100; final int HEIGHT = 175; BufferedImage[] images = new BufferedImage[origs.length]; AffineTransform at; for(int j = 0; j < origs.length; j++) { images[j] = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = images[j].createGraphics(); g2.setPaint(bgColor); g2.fillRect(0, 0, WIDTH, HEIGHT); // scale to fit double xScale = (double)WIDTH / origs[j].getWidth(); double yScale = (double)HEIGHT / origs[j].getHeight(); double scale = Math.min(xScale, yScale); // center thumbnail image double x = (WIDTH - origs[j].getWidth() * scale)/2; double y = (HEIGHT - origs[j].getHeight() * scale)/2; at = AffineTransform.getTranslateInstance(x, y); at.scale(scale, scale); g2.drawRenderedImage(origs[j], at); g2.dispose(); } return images; }
private BufferedImage[] loadImages() { String prefix = "images\\"; String ext = ".jpg"; String[] fileNames = { "2", "3", "5", "2" }; BufferedImage[] images = new BufferedImage[fileNames.length]; for(int j = 0; j < fileNames.length; j++) try { URL url = getClass().getResource(prefix + fileNames[j] + ext); images[j] = ImageIO.read(url); } catch(MalformedURLException mue) { System.out.println("url: " + mue.getMessage()); } catch(IOException ioe) { System.out.println("read: " + ioe.getMessage()); } return images; } } ************************************************************ Here in the codes the file names are clearly given in the code and so those images are displayed... But now i want to display any image of the local drives according to user click on the JTree.. I am sure i need to change particularly this method... private BufferedImage[] loadImages() { }
But i dont know what to change in this method... Please help
Waiting for your reply... Thank you I really need it for college project...
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35247
7
posted
0
You need to start by adding a JTree object to your GUI that reflects the local file system. But people here are not just going to write the code for you. Tells us where you are stuck implementing that, and we'll help you get going again.
Moving to the AWT/Swing forum, as there seems to be nothing applet-specific about the question.