Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Adding JScrollPane

$
0
0
I'm trying to add JScrollPane to a JDialog that opens on button clicks.....It is not working. When I resize the window i get a glimpse of the scrollpane but it's not working properly at all.....Any assistance would be appreciated

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;


public class Test extends JPanel {
	
	
	public Test(){
		testing();
	}
	
	public void testing() {
	
	JPanel panel = new JPanel();
	panel.add(new JLabel("Hello"));
	JButton button = new JButton("Hello");
	JButton button2 = new JButton("Button2");

	final JDialog dialog = new JDialog();
	dialog.setVisible(false);
	dialog.setSize(800,800);
	dialog.setLocation(395, 10);
	final JEditorPane pane = new JEditorPane();
	pane.setEditable(false);
	
	JScrollPane scroll = new JScrollPane(pane); //scroll pane code added
	scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
	scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
	dialog.getContentPane().add(scroll);
	dialog.validate();
	
	button.addActionListener(new ActionListener(){
		
		public void actionPerformed(ActionEvent e) {
			
						
			dialog.setVisible(true);
			
			URL url = null;
			try {
				//File file = new File("Safari for MAC.htm");
				//url = file.toURI().toURL();
				url = new URL("http://fay.iniminimo.com/paint7.html");
			} catch (MalformedURLException e1) {
				// TODO Auto-generated catch block
				
				e1.printStackTrace();
				
			}
			finally {
				System.out.println("Fucked UP");
			}
			try {
				
				pane.setPage(url);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}		
			dialog.add(pane);
			
		}
	
	});
button2.addActionListener(new ActionListener(){
		
		public void actionPerformed(ActionEvent e) {
			
			dialog.setVisible(true);
			
			URL url = null;
			try {
				//File file = new File("RBC Helper.htm");
				//url = file.toURI().toURL();
				url = new URL("http://www.google.ca");
			} catch (MalformedURLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {
				
				pane.setPage(url);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}		
			dialog.add(pane);
			
		}
	
	});
	
	
	panel.add(button);
	panel.add(button2);
	this.add(panel);
	
	
	
	
	}


public static void main(String[] args){
	
	JFrame frame = new JFrame();
	
	
	frame.setSize(400,400);
	
	Test test = new Test();
	
	frame.add(test);
	frame.setVisible(true);
	//frame.validate();
	

}
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles