如何在拆分窗格的一侧显示图像列表

时间:2014-05-26 19:51:47

标签: java user-interface imagej

我想制作一个分割窗格,在左侧显示一个图像列表,一旦您点击这些图像,它应该在右侧显示更大尺寸的图像。我想知道是否有人知道如何做到这一点,因为我似乎无法在拆分窗格的左侧创建图像列表(图像图标)。我可以阅读并打开.dcm图像(使用ImageJ),它们显示在内部框架中,但我不能使它在分割窗格中工作。如果有人对如何使这项工作有一个通用的解决方案,那将非常有帮助。提前致谢。

所以这是我的代码,在左侧显示问题列表,然后在拆分窗格的右侧显示有关它的更多信息。我想知道如何将左侧的图像图标列表。因此,如果单击图像,它将显示在右侧。

public class FrequentQuestions implements ActionListener, InternalFrameListener{

private int openFrameCount;
private JDesktopPane desk;
private JTextArea Tarea;
private JScrollPane scroll;
private BufferedReader in ;
JPanel panelQuestions = new JPanel();
JPanel panelAnswers = new JPanel();
JTextArea text = new JTextArea();
JTextPane tPane = new JTextPane();
String file ="";
//private FrequentQuestions quest;
JSplitPane pane ;
MyInternalFrame frame;


public FrequentQuestions(JDesktopPane desktop) {
    // TODO Auto-generated constructor stub
    desk = desktop;
}

@Override
public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    if(frame == null || frame.getParent() == null){
    frame = new MyInternalFrame("Frequently Asked Questions");

    String [] options = {"How to open/save images", "What formats can SAD Imaging open", "How to show information about an image"};
    JList list = new JList(options);
    //list.setBorder(BorderFactory.createLineBorder(Color.black));
    //panelQuestions.add(list);
    list.addListSelectionListener(new ListSelectionListener(){

        @Override
        public void valueChanged(ListSelectionEvent e) {
            // TODO Auto-generated method stub
            if(e.getValueIsAdjusting() == false)
                return;

            String [] options2 = {"hello","bye"};
            JList list2 = new JList(options2);
            JList list = (JList) e.getSource();


            if (list.isSelectionEmpty()) {
                System.out.println("list selection is empty!");
            }

                int index = ((JList)e.getSource()).getSelectedIndex();
                if(index == 0){
                    //panelAnswers.removeAll();
                    file = "";
                    try {
                        in = new BufferedReader(new FileReader("openSave.txt"));
                    } catch (FileNotFoundException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    String line;

                    try {
                        while((line = in.readLine()) != null)
                        {
                            System.out.println(line);
                            file += line;
                            file +="\n";

                        }
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    try {
                        in.close();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    tPane.setText(file);
                    System.out.println("I am outputting!");
                }
                else if(index == 1){
                    //panelAnswers.removeAll();
                    file = "";
                    try {
                        in = new BufferedReader(new FileReader("format.txt"));
                    } catch (FileNotFoundException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    String line;
                    //String file = ""; 
                    try {
                        while((line = in.readLine()) != null)
                        {
                            System.out.println(line);
                            file += line;
                            file +="\n";

                        }
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    try {
                        in.close();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    tPane.setText(file);
                    System.out.println("2nd item selected");

                }
                else{
                    //panelAnswers.removeAll();
                    file = "";
                    try {
                        in = new BufferedReader(new FileReader("showInfo.txt"));
                    } catch (FileNotFoundException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    String line;

                    try {
                        while((line = in.readLine()) != null)
                        {
                            System.out.println(line);
                            file += line;
                            file +="\n";

                        }
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    try {
                        in.close();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    tPane.setText(file);
                    System.out.println("3rd item selected");
                }

        }

    });

    JScrollPane scroll1 = new JScrollPane(list,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll = new JScrollPane(tPane,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scroll1, scroll);
    pane.setAutoscrolls(true);
    pane.setOpaque(true);

    panelQuestions.setMinimumSize(new Dimension(259,50));
    panelQuestions.setBackground(new Color(0,0,0,0));
    panelAnswers.setMinimumSize(new Dimension(600,30));
    pane.setOneTouchExpandable(true);
    pane.setDividerLocation(290);
    scroll1.setBackground(new Color(0,0,0,0));
    //Border border = new Border();
    //scroll1.setBorder(BorderFactory.createLineBorder(Color.black));

    frame.add(pane);
    frame.setVisible(true);
    desk.add(frame);

     try {
            frame.setSelected(true);
    } catch (java.beans.PropertyVetoException e1) {

    }
    }
    else{
        try {
            //frame.setIcon(true);
            //frame.setMaximizable(true);

            frame.setSelected(true);
            frame.moveToFront();
            //frame.toFront();
        } catch (PropertyVetoException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }

}

private class MyInternalFrame extends JInternalFrame {

    static final int xPosition = 30, yPosition = 30;
    public MyInternalFrame(String title) {
        super(title, true,true, true, true);
        setSize(800,500);

        // Set the window's location.
        setLocation(xPosition * openFrameCount, yPosition * openFrameCount);
    }
}

@Override
public void internalFrameActivated(InternalFrameEvent arg0) {
    // TODO Auto-generated method stub

}

@Override
public void internalFrameClosed(InternalFrameEvent arg0) {
    // TODO Auto-generated method stub
    frame = null;
}

@Override
public void internalFrameClosing(InternalFrameEvent arg0) {
    // TODO Auto-generated method stub
    frame = null;
}

@Override
public void internalFrameDeactivated(InternalFrameEvent arg0) {
    // TODO Auto-generated method stub

}

@Override
public void internalFrameDeiconified(InternalFrameEvent arg0) {
    // TODO Auto-generated method stub

}

@Override
public void internalFrameIconified(InternalFrameEvent arg0) {
    // TODO Auto-generated method stub

}

@Override
public void internalFrameOpened(InternalFrameEvent arg0) {
    // TODO Auto-generated method stub

}
}

1 个答案:

答案 0 :(得分:0)

 //Create the list of images and put it in a scroll pane.
    list = new JGridPanel(1, imageNames.length);
    JScrollPane pictureScrollPane = new JScrollPane(picture);

    for (int i=0; i < imageNames.length; i++) {
        picture = new JButton();
        picture.setBackground(Color.black);
        ImageIcon img = createImageIcon("images/" + "#FileName" + ".gif");
        picture.setIcon(img);
        list.setComponent(picture, 0, i);

    }

    //Create a split pane with the two scroll panes in it.
    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
            list, pictureScrollPane);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(150);

    //Provide minimum sizes for the two components in the split pane.
    Dimension minimumSize = new Dimension(100, 50);
    list.setMinimumSize(minimumSize);
    pictureScrollPane.setMinimumSize(minimumSize);

    //Provide a preferred size for the split pane.
    splitPane.setPreferredSize(new Dimension(400, 200));

并使用this class作为JGridPanel。