1 Replies - 906 Views - Last Post: 04 June 2011 - 08:59 AM

#1 neilimage  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-June 11

image not displaying on panel2 of splitpane

Posted 04 June 2011 - 08:21 AM

is there anything wrong with the openFile or is thr something else missing?
because when i load the image using JFileChooser it gets loaded (the frame name changes to image name) but its doesent display. is thr any problem with the splitpane??
here is the code


import javax.swing.*;

import java.awt.*;

import javax.swing.border.BevelBorder;
import javax.swing.border.EtchedBorder;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.io.*;
import java.awt.image.*;
import java.util.Iterator;
import java.awt.geom.*; 
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;

import javax.swing.border.*;
import java.awt.color.*;

public class neil extends JFrame implements ActionListener 
{
 BufferedImage image,img;
 public JMenuBar menuBar;
 JMenuItem grey,open;
 JMenu file,edit;
 JPanel panel1,panel2;
 JButton negativeB,embossB,brightB,sharpB,blurB,greyB,zoominB,zoomoutB,editT,openT,saveT,oriT,helpT;
 JLabel jb;
 Graphics g;

 neil()
{
  
 try
  {
  JFrame frame = new JFrame();
  setTitle("FINAL LAYOUT");
 // setUndecorated(true);
 //getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
  panel1=new JPanel();
  panel2=new JPanel();
  JLabel j1 = new JLabel("Area 1");
  JLabel j2 = new JLabel("Area 2");
 //panel1.add(j1);
  panel2.add(j2);
  JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 
                true, panel1, panel2);
    panel1.setLayout(new GridLayout(8,2));
    //panel1.setLayout(new BorderLayout());
    //splitPane.setOneTouchExpandable(true);
    splitPane.setDividerSize(2); 
    splitPane.setDividerLocation(165);
   // splitPane.getMaximumDividerLocation();

     getContentPane().add(splitPane);
     //JLabel jb=new JLabel(" to checck snsn snsna nsns  nsnnnnnnn nssnshshs uohoh dhbgfdjgsgjgfgdfgsdgfsdgsgfsdfgsd weather 

//scccroll is working");
     splitPane.setPreferredSize(new Dimension(100,300));

  
      //JLabel jb=new JLabel

("dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");
       JScrollPane jScrollPane = new JScrollPane();
     jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
     jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
     splitPane.setRightComponent(jScrollPane);
    // splitPane.setResizeWeight(50.525);
    // splitPane.setMaximumSize(200,100);
    
     
  //setContentPane(panel);
  setSize(500,400);
  setVisible(true);
  
  //buttons in first panel
  
  brightB = new JButton(new ImageIcon("C://Bright.gif"));
  panel1.add(brightB);
  brightB.setVisible(false);
  brightB.addActionListener(this);
  brightB.setToolTipText("Bright");

  embossB= new JButton(new ImageIcon("C://Emboss.gif"));
  panel1.add(embossB);
  embossB.setVisible(false);
  embossB.addActionListener(this);
  embossB.setToolTipText("Emboss");
  
  sharpB = new JButton(new ImageIcon("C://Sharp.gif"));
  panel1.add(sharpB);
  sharpB.setVisible(false);
  sharpB.addActionListener(this);
  sharpB.setToolTipText("Sharp");
  
   greyB = new JButton(new ImageIcon("C://grey.png"));
   panel1.add(greyB); 
   greyB.addActionListener(this);
   greyB.setVisible(false);
   greyB.setToolTipText("Grey");
   
   zoominB = new JButton(new ImageIcon("C://Zoomin.gif"));
   panel1.add(zoominB);
   zoominB.setVisible(false);
   zoominB.addActionListener(this);
   zoominB.setToolTipText("Zoomin");
   
   zoomoutB= new JButton(new ImageIcon("C://Zoomout.gif"));
   panel1.add(zoomoutB);
   zoomoutB.setVisible(false);
   zoomoutB.addActionListener(this);
   zoomoutB.setToolTipText("Zoomout");
   
   negativeB = new JButton(new ImageIcon("C://Negative.gif"));
   panel1.add(negativeB);
   negativeB.setVisible(false);
   negativeB.addActionListener(this);
   negativeB.setToolTipText("Negative");

    blurB = new JButton(new ImageIcon("C://Blur.gif"));
    panel1.add(blurB); 
    blurB.setVisible(false);
    blurB.addActionListener(this);
    blurB.setToolTipText("Blur");

   /* brightB = new JButton(new ImageIcon("C://Bright.gif"));
    panel1.add(brightB);
   embossB= new JButton(new ImageIcon("C://Emboss.gif"));
    panel1.add(embossB);
    sharpB = new JButton(new ImageIcon("C://Sharp.gif"));
   panel1.add(sharpB);
   greyB = new JButton(new ImageIcon("C://Gray.gif"));
     panel1.add(greyB); 
     brightB = new JButton(new ImageIcon("C://Bright.gif"));
     panel1.add(brightB);
    embossB= new JButton(new ImageIcon("C://Emboss.gif"));
     panel1.add(embossB);
     sharpB = new JButton(new ImageIcon("C://Sharp.gif"));
    panel1.add(sharpB);
    greyB = new JButton(new ImageIcon("C://Gray.gif"));
      panel1.add(greyB); */
  //ho gaya :)/> 

  menuBar = new JMenuBar();
  menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
  
  file = new JMenu("File");
  open = new JMenuItem("open");
  file.add(open);
 open.addActionListener(this);
  
  edit = new JMenu("Edit");
  grey = new JMenuItem("Greyscale");
  edit.add(grey);
  
  menuBar.add(file);
  menuBar.add(edit);
  setJMenuBar(menuBar);
  
  //TOOLBAR buttons
  JToolBar toolbar = new JToolBar("Toolbar", JToolBar.HORIZONTAL);
  openT = new JButton(new ImageIcon("C://open.png"));
  toolbar.add(openT);
  openT.addActionListener(this);
  openT.setToolTipText("Open");
  
  saveT = new JButton(new ImageIcon("C://save.png"));
  toolbar.add(saveT);
  saveT.addActionListener(this);
  saveT.setToolTipText("Save");
  
  helpT = new JButton(new ImageIcon("C://help.png"));
  toolbar.add(helpT);
  helpT.addActionListener(this);
  helpT.setToolTipText("Help");
  
  
  editT= new JButton(new ImageIcon("C://edit.png"));
  toolbar.add(editT);
  editT.addActionListener(this);
  editT.setToolTipText("Edit");
  
  
  oriT= new JButton(new ImageIcon("C://Original.gif"));
  toolbar.add(oriT);
  oriT.addActionListener(this);
  oriT.setToolTipText("Original");
  
  getContentPane().add(toolbar,BorderLayout.NORTH);
 //done
 }
  catch(Exception e)
			{
			/*System.out.println("error:"+e.getMessage());
			}
			setContentPane(new JPanel()
			{
		
			private static final long serialVersionUID = 1L;

			public void paint(Graphics g)
			{
			g.drawImage(image,0,0,this);
			}
			});*/
			} 
  /*setLeftComponent
  setRightComponent
  setTopComponent
  setBottomComponent*/
  
  }

public void actionPerformed(ActionEvent e)
	{
		
		if((e.getSource()==open) || (e.getSource()== openT ))                         
		{ 
             openFile();
        }
		else if(e.getSource()== editT )
		{
			 greyB.setVisible(true);
			 embossB.setVisible(true);
			 sharpB.setVisible(true);
			 zoominB.setVisible(true);
			 zoomoutB.setVisible(true);
			 greyB.setVisible(true);
			 brightB.setVisible(true);
			 negativeB.setVisible(true);
                         blurB.setVisible(true);
		}
		
                  }


public void openFile()
	{
	try
	{
	JFileChooser chooser = new JFileChooser();
	//chooser.setCurrentDirectory(new File("."));
	int r = chooser.showOpenDialog(this);
	if (r != JFileChooser.APPROVE_OPTION) return;
	File f = chooser.getSelectedFile();
	String name = f.getName();

	image=ImageIO.read(chooser.getSelectedFile());
	//box.add(new JLabel(new ImageIcon(image)));
	//panel.add(new JScrollPane(box));
	setSize(image.getWidth(), image.getHeight());
	setTitle(name);
	
     
        }

	catch(Exception e)
	{
	}
	}



public static void main(String[] args) 
{
 new neil(); 
}
}



Is This A Good Question/Topic? 0
  • +

Replies To: image not displaying on panel2 of splitpane

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,065
  • Joined: 27-December 08

Re: image not displaying on panel2 of splitpane

Posted 04 June 2011 - 08:59 AM

Please do not duplicate and cross-post.

Topic closed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1