loading images in swings

Hi to all,

I use JSplitpane to to split two panels(left and right),

left panel contains JTree, right panel is loading the required images when i click the corresponding node in the JTree.

images came from database .

Based on the images length i created required JLables and set it to the images.

Initially i am loading images in the right panel (i.e fine), But i am clicking the node in the JTree, right Panel images are not refreshed with new one.

Please help me,

Posted On: Monday 22nd of October 2012 09:41:47 PM Total Views:  246
View Complete with Replies

Related Messages:

Issue while loading images packaged in jar   (125 Views)
I have used icons for buttons in my applications.Below code is able to load images when it is run from IDE(eclipse). But when I package everything in a jar file the images are not getting loaded. Find the attachment to view the jar contents. Can you please let me know what should I do to load those images packaged inside jar file I'm using the below code. JButton menuButton=null; menuButton= PMUtil.createMenuButton(..,"monitor.png",..,..,..)
Issue while loading images.   (109 Views)
Please find the below code.Please let me know what changes shall I make to load the images.PFA below the project structure. package tst; import java.awt.GridLayout; import; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Starter extends JFrame{ public Starter(){ this.getContentPane(); this.setLayout(new GridLayout(1,1)); JPanel jPanel=new JPanel(); JButton jButtonDeploy=new JButton(); JButton jButtonMonitor=new JButton(); JButton jButtonRepo=new JButton(); JButton jButtonPM=new JButton(); URL imgURL=this.getClass().getResource("./images/deploy.png"); if(imgURL !=null){ jButtonDeploy.setIcon(new ImageIcon(imgURL)); }else{ System.out.println("resources not found"); } imgURL=this.getClass().getResource("repo.png"); if(imgURL !=null){ jButtonRepo.setIcon(new ImageIcon(imgURL)); }else{ System.out.println("resources not found"); } imgURL=this.getClass().getResource("images/monitor.png"); if(imgURL !=null){ jButtonMonitor.setIcon(new ImageIcon(imgURL)); }else{ System.out.println("resources not found"); } ClassLoader cl = this.getClass().getClassLoader(); imgURL=cl.getResource("PM.png"); if(imgURL !=null){ jButtonPM.setIcon(new ImageIcon(imgURL)); }else{ System.out.println("resources not found"); } jPanel.setLayout(new GridLayout(4,1)); jPanel.add(jButtonDeploy); jPanel.add(jButtonMonitor); jPanel.add(jButtonRepo); jPanel.add(jButtonPM); this.add(jPanel); } public static void main(String[] args) { Starter tst=new Starter(); tst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tst.setVisible(true); tst.setSize(230,300); } }
including browse button for loading images   (120 Views)
Sir......... any one tel me the procedure to include browse button for loading an image after that saving it into MySql Database.
Lazy loading of image in table cell with custom renderer   (154 Views)
I have a table with a custom cell renderer made from a custom component that includes a JLabel with an ImageIcon. The images for the ImageIcons have to be downloaded from Amazon Web Services, and this takes awhile. I'd like the textual parts of the custom component to display right away, and the images to be added as they become available. But the obvious way of handling this (start a background thread to download the image; update the JLabel when it completes) doesn't work, presumably because of the peculiar way custom renderers are handled (same renderer used for multiple cells, so that renderer.repaint() does nothing). Currently I am just getting the image and updating the JLabel with it in the custom component's getTableCellRendererComponent() method. This means that all the images are downloaded before any of the table's cells are painted. I've spent a fair while struggling with this; I'd be very interested to learn what the solution might be, if there is one.
waiting or loading screen in java   (78 Views)
, i am running a program that execute quite a numbers of loop. the program will not be responsive when running with those loop. i want to create a form that stay on top of the program and notify the user about the progress of execution. How can i do that i try to google the example but no luck. and the clue point me to use threading which i am not really good at (know a bit). can anyone show me a very simple coding regarding to this problem just a simple waiting form stay on the main form when the main program is executing a huge loop. after loop finish, the waiting screen gone.
NullPointer on loading ImageIcon   (74 Views)
Hi Guys, I wonder if you can help me. I am trying to load an image (PNG) into an ImageIcon. But all I get is a NullPointerException wherever I place the image. My code: public static ImageIcon getImageIcon(String name) { return new ImageIcon(ClassLoader.getSystemResource(name)); }
Problem in reloading graphics object.   (83 Views)
I am very new to swing and java awt. I am trying an application where I have 2 panels in main container. First panel (p1)contains some data and a button , upon click of button, Second panel (p2) has to draw a graph based on the content of first panel. To draw the graph I am creating another class called secondPanel and passing p2 in the constructor, to get the graphics object of p2 to draw the graph. The problem I am getting is when I change the data and redo the graph it retains the old graph. As I understand it is because of the graphics object that I am getting from p2. before passing object p2 to the constructor of SecondPanel, I am calling remove() and validate() on p2, however my graphics object is not recreated. Really appreciate if someone can help me here. Here is the code snippet of SecondPanel. import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.font.FontRenderContext; import java.awt.font.LineMetrics; import java.awt.geom.AffineTransform; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import javax.swing.JPanel; public class SecondPanel extends JPanel{ JPanel p ; public SecondPanel(JPanel panel){ this.p = panel; p.remove(); p.revalidate(); paintComponent(p.getGraphics()); } private Double[] years1; //private Double[] data1; /* public Double[] getData1() { return data1; } public void setData1(Double[] data) { this.data1 = data; }*/ public Double[] getYears1() { return years1; } public void setYears1(Double[] years) { this.years1 = years; } Double[] data2 = new Double[5];// { 230, 1340, 6500, 330 }; int[] years = { 1995, 1996, 1997, 1998 }; final int PAD = 20; final int VPAD = 45; final int HPAD = 55; final int TICK = 2; final int STICK = 3; //chnages by mamta Double[] data = GraphAppl2.dja.toArray(data2); int dataLength = GraphAppl2.dja.size(); protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); drawAxes(g2); // plot data Point2D.Double lastP = null; for(int j = 0; j < data.length; j++) { g2.setPaint(; Point2D.Double p = modelToView(j, data[j]); g2.fill(new Ellipse2D.Double(p.x-2, p.y-2, 4, 4)); if(lastP != null) { g2.setPaint(; g2.draw(new Line2D.Double(lastP, p)); } lastP = p; } } private void drawAxes(Graphics2D g2) { double w = p.getWidth(); double h = p.getHeight(); // Double[] data2 = this.getData(); System.out.println("data length is " + data.length); double xInc = (w - HPAD-PAD)/(dataLength-1); int max = (int)Math.ceil(getMaxValue()); double yInc = (h - PAD-VPAD)/max; // grid lines g2.setPaint(new Color(220,230,240)); // vertical for(int j = 0; j
Help me reducing JTABLE loading time..   (68 Views)
Hi my small application loads connected agents with properties in a jtable. *Connected agents are are some process which are listening to some port. If I have 30 agents and out of 20 are connected. So I have to load 20 agents in the table. But when the application loads.. my swing application hangs as it takes time to see if all the agents are connected and then load only connected agents. Is this possible to load a connected in the jtable as soon as we figure out those are connected. So that swing application do not be in loading state. and update the jtable successively
JTabbedPane problems - not loading correctly   (98 Views)
I think i don't have something set correctly, but when I try to use JTabbedPanes it never loads correctly. If I have 3 tabs, tab 3 loads up first and I have to select all the tabs at least once before it works correctly. Here is an example of what i mean. I used this program written by Dave Marshall to see where i was messing up, but i get the same problem when i run it.m Any help would be great! -------------------------- import java.awt.*; import javax.swing.*; class TabbedPaneExample extends JFrame { privateJTabbedPane tabbedPane; privateJPanelpanel1; privateJPanelpanel2; privateJPanelpanel3; public TabbedPaneExample() { setTitle( "Tabbed Pane Application" ); setSize( 300, 200 ); setBackground( Color.gray ); JPanel topPanel = new JPanel(); topPanel.setLayout( new BorderLayout() ); getContentPane().add( topPanel ); // Create the tab pages createPage1(); createPage2(); createPage3(); // Create a tabbed pane tabbedPane = new JTabbedPane(); tabbedPane.addTab( "Page 1", panel1 ); tabbedPane.addTab( "Page 2", panel2 ); tabbedPane.addTab( "Page 3", panel3 ); topPanel.add( tabbedPane, BorderLayout.CENTER ); } public void createPage1() { panel1 = new JPanel(); panel1.setLayout( null ); JLabel label1 = new JLabel( "Username:" ); label1.setBounds( 10, 15, 150, 20 ); panel1.add( label1 ); JTextField field = new JTextField(); field.setBounds( 10, 35, 150, 20 ); panel1.add( field ); JLabel label2 = new JLabel( "Password:" ); label2.setBounds( 10, 60, 150, 20 ); panel1.add( label2 ); JPasswordField fieldPass = new JPasswordField(); fieldPass.setBounds( 10, 80, 150, 20 ); panel1.add( fieldPass ); } public void createPage2() { panel2 = new JPanel(); panel2.setLayout( new BorderLayout() ); panel2.add( new JButton( "North" ), BorderLayout.NORTH ); panel2.add( new JButton( "South" ), BorderLayout.SOUTH ); panel2.add( new JButton( "East" ), BorderLayout.EAST ); panel2.add( new JButton( "West" ), BorderLayout.WEST ); panel2.add( new JButton( "Center" ), BorderLayout.CENTER ); } public void createPage3() { panel3 = new JPanel(); panel3.setLayout( new GridLayout( 3, 2 ) ); panel3.add( new JLabel( "Field 1:" ) ); panel3.add( new TextArea() ); panel3.add( new JLabel( "Field 2:" ) ); panel3.add( new TextArea() ); panel3.add( new JLabel( "Field 3:" ) ); panel3.add( new TextArea() ); } // Main method to get things started public static void main( String args[] ) { // Create an instance of the test application TabbedPaneExample mainFrame= new TabbedPaneExample(); mainFrame.setVisible( true ); } }
A gray color box appear d when loading image on JPanel   (92 Views)
Hai , I m nikhil. I have a doubt that when I load an image in to jpanel using drawImage method of Graphics (G.drawImage(Image img,int width,int higth))...It take more time to load. When loading a gray color box will be appear on Frame. Then image loaded.How to avaoid this gray color. I think i will get a solution from javaranch
printing html and images using JEditorPane   (292 Views)
hi i am working on printing multiple html and images(png) in a single batch.. i am able to print all in a single batch if html files are single page files but if they are multipage files i am unable to print them. i am rendering html to a JEditorPane. i can print multiple multipage html files in a single batch but unable to do html files and images in a single batch .. anyone can help me thanx in advance -if you want i can provide code bye madhu
saving transformed images   (71 Views)
Hi all I'm using awt for rotating images that are kept in DB blobs. The problem is that when I saved the rotated image to the DB, it appears as if its raster has the wrong dimentions. The visual affect of this problem is that the image is cut on its wide side, and a black area is added to its narrow side. This is as if after the rotation - the raster turns to a square. Here is a snippet from the code: BufferedImage originalImage = ByteArrayInputStream(originalImageAsBytes)); // read the original image AffineTransform rotationTransform = new AffineTransform(); rotationTransform.rotate(radians, originalImage.getWidth() / 2.0 , originalImage.getHeight() / 2.0); AffineTransformOp rotationTransformOp = new AffineTransformOp(rotationTransform , AffineTransformOp.TYPE_NEAREST_NEIGHBOR); // this AffineTransformOp is the actual "rotater" BufferedImage rotatedImage = rotationTransformOp.filter(originalImage,null); // perform the rotation // write the result rotatedImageStream = new ByteArrayOutputStream(); ImageIO.write(rotatedImage, ii.getFormatName() , rotatedImageStream);
loading resultsets in multiple threads in a swing application   (75 Views)
Hi all, I am in the process of developing a J2EE/Swing application. I need to load huge chunks(approx 2000 records) of result set data into a swing grid. How do I speed up this loading huge chunk of data into the swing grid Is there a way that I use threads, where in one thread populates a set of data and as the user moves the scroll bar down, i start another thread which loads another set of data and which continues untill all the data loading is finished. One of my friends gave me this idea. but i really dont how to realise this in the code. Is there any such code available on the web or did anyone had this task before and tried it the same way. Help pls. Seshadri Meharwade Srinivas
Transparent popup-images with swing   (61 Views)
Hi! I have a very cheesy problem. I want to make a program that will fill my gf's screen with hearts, but I don't know how to go about it. I want to use high quality transparent png files for the hearts, and i don't want them to have a border or be square or anything. I don't even know what to google for this, so I thought I would ask here Please help (for love!)
Problem changing images   (62 Views)
, I writting a program where I upload pictures from students, i mean one student can have many pictures. I save all those pictures path into the database. I have a panel where you can watch the pictures on a label. I create an ImageIcon(image.path) and put it into the label. I try to see the pictures one by one with a preview and next button. The problem is that when you go to the next picture if the picture is to heavy it goes really really slow, and sometimes it gives an out of bound of memory error. Please I need help, i need to finish this by tomorrow.
Doubt in JFrame and loading Dynamic JPanel   (70 Views)
Hai Experts , I need some suggestions for the below scenario, my screen has two panels one is in left side & another is in right side of the screen.while opening the main screen I am having 3 buttons on the left side panel and none in the right side panel.If i clicked the 1st button 2 labels,2 text fields and 2 buttons should be displayed on the right side panel.I am having these components in a separate class file which extends a JPanel.Only in the run time i want to add this class file(as component) to the right side panel in the main screen. Can any one guide how to make it possible
annoying images   (61 Views)
When I run this code lynxIcon pops up but rabbitIcon does not. I have tried everything. The file does exist, it compiles and runs without a problem, the System.out.println(rabbitIcon); prints out a valid definition and I have no clue what to try next. package com.googlepages.kpcode.LynxVsRabbit; import java.awt.*; import java.awt.event.*; import javax.swing.*; class Art extends JPanel implements ActionListener { public static JButton go; //they guy who starts it all public static JTextArea stats; //lists the standings public static JFrame frame; //the head honcho who shows everything else public static ShapeIcon lynxIcon; //a well drawn picture of a lynx public static ShapeIcon rabbitIcon; //a even better drawn rabbit public static Art canvas; //me! static { //initializes our ShapeIcon lynxIcon = new ShapeIcon(Art.class.getResource("/image/lynx.gif")); System.out.println(lynxIcon); rabbitIcon = new ShapeIcon(Art.class.getResource("/image/rabbit.gif")); System.out.println(rabbitIcon); } //I left out some irrelevant code here public void initGui() { //this method sets up the gui so that we can see it and it can be amazing //Make the components frame = new JFrame("Lynx Vs Rabbits - (C) 2008 Kolten Pearson - GNU public license"); //nice (C) statment, right go = new JButton("go"); stats = new JTextArea("hit go"); //tell the button what to do go.addActionListener(this); //make it so they can not type things in stats stats.setEditable(false); //stick them all into the frame frame.getContentPane().add(this); frame.getContentPane().add(BorderLayout.SOUTH, go); frame.getContentPane().add(BorderLayout.EAST, stats); frame.setSize(500, 500); //how big our window is in pixels frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //make it so when they hit the X button I go away :( frame.setVisible(true); //now we step out of the dark, musty processing unit and into the bright, sunny desktop } //end of initGui: the GUI is set up public void actionPerformed(ActionEvent ev) { //what the button does stats.setText("you hit go!!!"); this.paintComponent(this.getGraphics(), 0, 50); } public void paintComponent(Graphics g) { //this is were we mess with colored pixels and animation System.out.println("repainted"); }//end of painting pixels public void paintComponent(Graphics g, int x, int y) { //overloaded method for drawing lynx g.drawImage(lynxIcon.getImage(), 50, 0, this); g.drawImage(rabbitIcon.getImage(), 0, 50, this ); System.out.println("lynx painted"); } }
splash screen with a progress bar loading "Help me"   (79 Views)
please help me, i am doing a project for the university but can't start. I am unable to load my progress bar in my splash form. none of my buttons are working. I badly need help. So please, do reply.
uploading image   (63 Views)
hi i am firing a simple question, although i know solution but i think it would be better to go along your way. i have an registration form made using japplets and japplets in tern embedded in jsp. at the bottom of the form i want to let applicants to upload his photo(image of any format) from either his terminals local drive or from any URI. for this accomplishment, what component should use as a container that would suit best
how to convert byte array to images   (274 Views)
hi folks i want to display some images in the jsp. by taking the images from DataBase ,i already inserted the image into the dataBase as a BLOB and i have retrived the image from DataBase as a byte array now i dont no how to convert the byte array to image iam using struts and hibernate eagerly waiting for your replies