Scroll bar to image

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vaani15
    New Member
    • Jun 2007
    • 6

    Scroll bar to image

    I am facing problem with appying the scroll bar. I have used JScrollPane, but its knob is nt functional. Can anybody help in how to use knob to see the image??
    Also each time i use the scroll bar to shift the image it takes a lot of time to refresh the image?? Please HELP!!!!
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by vaani15
    I am facing problem with appying the scroll bar. I have used JScrollPane, but its knob is nt functional. Can anybody help in how to use knob to see the image??
    Also each time i use the scroll bar to shift the image it takes a lot of time to refresh the image?? Please HELP!!!!
    I'm not sure now if the page knob is working or not. But the reason why the image takes long to load may be due to how you have written the code to diplay it. Perhaps if you show that someone may be able to pick where the delay is coming from.

    Comment

    • vaani15
      New Member
      • Jun 2007
      • 6

      #3
      Originally posted by r035198x
      I'm not sure now if the page knob is working or not. But the reason why the image takes long to load may be due to how you have written the code to diplay it. Perhaps if you show that someone may be able to pick where the delay is coming from.
      Actually i have not applied any code for the knob. Please supply any code if possible that can be used to scroll the image. Here the code which i have used.
      Please HELP!!!
      Code:
      public FrameBuilder(int type, ChartPanel panel,
      			AbstractChartDataModel data, PieChartRenderer chartRenderer) {
      		//panel.setVisible(true);
      		SelectGraphScreen.frame1.setVisible(false);
      		//this.setLayout(null);
      		this.setResizable(false);
      		this.setUndecorated(false);
      		System.out.println("Screen size : " + scrnsize);
      		this.setBounds(0, 0, width, height);
      		/* to be finalised for actual change in line below */
      		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      		this.data = data;
      		this.panel = panel;
      		panel.setBounds(0, 0, width - 25, height);
      		System.out.println(" chart panel bounds :" + panel.getHeight() + "  "
      				+ panel.getWidth());
      		panel.setPreferredSize(new Dimension(400, 300));
      		this.chartRenderer = chartRenderer;
      
      		panel2 = new JPanel();
      		panel3 = new JPanel();
      
      		backButton = new JButton("Back");
      		saveButton = new JButton("Save As");
      		closeButton = new JButton("Close");
      
      		JPGRadioButton = new JRadioButton("jpg ");
      		PNGRadioButton = new JRadioButton("png");
      		JPGRadioButton.setBackground(Color.white);
      		PNGRadioButton.setBackground(Color.white);
      		JPGRadioButton.setSelected(true);
      	
      		/*JPGRadioButton.setBounds(20,20,10,10);
      		 PNGRadioButton.setBounds(20,20,24,10);
      		 saveButton.setBounds(20,20,38,10);
      		 */
      
      		int panelHeight = (int) ((18 * height) / 20);
      		int panelWidth = (int) ((2 * width) / 3);
      
      		panel2.setBackground(Color.white);
      		panel2.setBounds(panelWidth, panelHeight, (width) / 3,
      				(int) (height / 14));
      		panel3.setBounds(0, panelHeight, panelWidth, (int) (height / 14));
      		panel3.setBackground(Color.white);
      
      		backButton.addActionListener(this);
      		saveButton.addActionListener(this);
      		closeButton.addActionListener(this);
      		if (type == Draw.PIE) {
      			panel.addMouseMotionListener(this);
      		}
      
      		ButtonGroup group1 = new ButtonGroup();
      		group1.add(JPGRadioButton);
      		group1.add(PNGRadioButton);
      		panel2.add(backButton);
      		panel2.add(closeButton);
      		panel2.add(JPGRadioButton);
      		panel2.add(PNGRadioButton);
      		panel2.add(saveButton);
      
      		jp = new JPanel();
      		jp.setPreferredSize(new Dimension(width, height));
      		jp.add(panel, BorderLayout.CENTER);
      		jScrollPane = new JScrollPane(panel);
      		
      
      		
      		System.out.println(" Scrollpane bounds:"
      				+ jScrollPane.getViewport().getViewSize());
      		jScrollPane
      				.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      		// jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      		jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
      		/* Now trying to add a split pane */
      		JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
      		if (panel == null) {
      			System.out.println("its null");
      		}
      		sp.setTopComponent(jScrollPane);
      		sp.setBottomComponent(panel2);
      		sp.setDividerLocation(panelHeight);
      
      		getContentPane().add(sp);
      		this.validate();
      		this.repaint();
      
      		panel.repaint();
      
      		System.out.println("***********************" + panel.isVisible());
      		System.out.println("***********************" + this.panel);
      		
      
      	}

      Comment

      Working...