SplitPanel and ImageIcon

D

David

Hello,
I'm starting with java and i'm having problems to display an image in a
splitpanel with a scrollbar.
I have different files but those required are described below. I think the
problem is coming from the file RightPanel.java here below does do not
display the image.
There is no problem of compilation , it works fine. Just that the image and
scrollbar are not displayed.
If anybody could help it would really be great.
thanks,.
david

FILE RightPanel

import javax.swing.*;

import java.awt.*;

public class RightPanel extends JPanel {

private JLabel picture;


RightPanel() {


ImageIcon pathImage = new ImageIcon("images/image.gif");

picture = new JLabel(pathImage);

JScrollPane imageDisplayPane = new JScrollPane(picture);


this.add(imageDisplayPane);

this.setSize(300,250);

this.setBackground(Color.white);

this.setVisible(true);

}



FILE SplitPanel.java :

import javax.swing.*;

import java.awt.*;

public class SplitPanel extends JPanel {

public SplitPanel() {

super();

final JList list;


LeftPanel leftp = new LeftPanel();

RightPanel rightp = new RightPanel();

JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

pane.setLeftComponent(leftp);

pane.setRightComponent(rightp);

pane.setDividerLocation(200);

pane.setDividerSize(10);


sion(400, 200));

setLayout(new GridLayout(1,1));

add(pane, new Dimension(1,1));


}

}





}

FILE: MainFrame.java

import javax.swing.*;

import java.awt.*;

public class MainFrame extends JFrame{


MainFrame() {


//Set properties

setTitle("viewer v1.0");



setSize(600,400);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


//Define container

Container pane = getContentPane();


//Set BorderLayout

BorderLayout border = new BorderLayout();

pane.setLayout(border);


pane.add(new SplitPanel());


setVisible(true);



}

}

FILE: Main.java

import javax.swing.*;

public class Main {

public static void main(String[] args) {

JFrame.setDefaultLookAndFeelDecorated(true);


MainFrame joe = new MainFrame();


}

}
 
A

ak

and try to set preferredSize of rightPanel


ak said:
try BorderLayout instead of GridLayout


David said:
Hello,
I'm starting with java and i'm having problems to display an image in a
splitpanel with a scrollbar.
I have different files but those required are described below. I think the
problem is coming from the file RightPanel.java here below does do not
display the image.
There is no problem of compilation , it works fine. Just that the image and
scrollbar are not displayed.
If anybody could help it would really be great.
thanks,.
david

FILE RightPanel

import javax.swing.*;

import java.awt.*;

public class RightPanel extends JPanel {

private JLabel picture;


RightPanel() {


ImageIcon pathImage = new ImageIcon("images/image.gif");

picture = new JLabel(pathImage);

JScrollPane imageDisplayPane = new JScrollPane(picture);


this.add(imageDisplayPane);

this.setSize(300,250);

this.setBackground(Color.white);

this.setVisible(true);

}



FILE SplitPanel.java :

import javax.swing.*;

import java.awt.*;

public class SplitPanel extends JPanel {

public SplitPanel() {

super();

final JList list;


LeftPanel leftp = new LeftPanel();

RightPanel rightp = new RightPanel();

JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

pane.setLeftComponent(leftp);

pane.setRightComponent(rightp);

pane.setDividerLocation(200);

pane.setDividerSize(10);


sion(400, 200));

setLayout(new GridLayout(1,1));

add(pane, new Dimension(1,1));


}

}





}

FILE: MainFrame.java

import javax.swing.*;

import java.awt.*;

public class MainFrame extends JFrame{


MainFrame() {


//Set properties

setTitle("viewer v1.0");



setSize(600,400);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


//Define container

Container pane = getContentPane();


//Set BorderLayout

BorderLayout border = new BorderLayout();

pane.setLayout(border);


pane.add(new SplitPanel());


setVisible(true);



}

}

FILE: Main.java

import javax.swing.*;

public class Main {

public static void main(String[] args) {

JFrame.setDefaultLookAndFeelDecorated(true);


MainFrame joe = new MainFrame();


}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top