Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JScrollPane问题高位置_Java_Swing_Jscrollpane - Fatal编程技术网

Java JScrollPane问题高位置

Java JScrollPane问题高位置,java,swing,jscrollpane,Java,Swing,Jscrollpane,我有一个JScrollPane问题,我无法切换到高位,我尝试了所有方法: setValue(0); setCaretPosition(0); getViewport().setViewPosition(new Point(0,0)); 最后所有 只有一件事是使用showMessageDialog才有效,但我更愿意避免 这是我代码的一部分: public class fenetre_departement { private static final long serialVersio

我有一个JScrollPane问题,我无法切换到高位,我尝试了所有方法:

setValue(0);
setCaretPosition(0);
getViewport().setViewPosition(new Point(0,0));
最后所有

只有一件事是使用showMessageDialog才有效,但我更愿意避免

这是我代码的一部分:

public class fenetre_departement {

    private static final long serialVersionUID = 1L;
    private JPanel container = new JPanel();

    private Vector<Component> sous_titreComp = new Vector<Component>();

    public JPanel getContainer() {
        return container;
    }

    public void setContainer(JPanel container) {
        this.container = container;
    }

    private ImageIcon icon;
    private ImageIcon icon2;
    private ImageIcon icon3;
    private JTextArea titre = new JTextArea("");
    private JTextArea texte = new JTextArea("");
    private JTextArea titre2 = new JTextArea("");
    private JTextArea texte2 = new JTextArea("");
    private JTextArea titre3 = new JTextArea("");
    private JTextArea texte3 = new JTextArea("");
    private JTextArea titre4 = new JTextArea("");
    private JTextArea texte4 = new JTextArea("");
    private JTextArea titre5 = new JTextArea("");
    private JTextArea texte5 = new JTextArea("");
    private JTextArea titre6 = new JTextArea(":");
    private JTextArea texte6 = new JTextArea("");
    private JTextArea titre7 = new JTextArea("");
    private JTextArea texte7 = new JTextArea("");

    private JScrollBar ascenceur;

    private JScrollPane dipScroll;

    public JScrollPane getDipScroll() {
        return dipScroll;
    }

    public void setDipScroll(JScrollPane dipScroll) {
        this.dipScroll = dipScroll;
    }

    private Color sous_titre;

    public fenetre_departement(){

    container.setLayout(new BorderLayout());



    //Construction du header
    JPanel top = new JPanel();
    icon = new ImageIcon(getClass().getResource("/images/header_small.jpg"),"Liste des étudiants");
    JLabel lbli2 = new JLabel(icon);
    top.add(lbli2);

    //construction du panneau central
    JPanel middle = new JPanel();
    middle.setLayout(new BoxLayout(middle,BoxLayout.PAGE_AXIS));
    titre.setOpaque(false);
    titre.setEditable(false);
    titre.setFont(new Font("Arial",Font.BOLD,16));
    //construction du panneau intermédiaire inclus dans le panneau central
    JPanel col1 = new JPanel();
    col1.setLayout(new BorderLayout());
    icon2 = new ImageIcon(getClass().getResource("/images/logo_dis.jpg"),"Liste des étudiants");
    JLabel lbli3 = new JLabel(icon2);
    texte.setOpaque(false);
    texte.setEditable(false);
    middle.add(titre);
    col1.add(lbli3, BorderLayout.WEST);
    col1.add(texte, BorderLayout.CENTER);
    middle.add(col1);
    //construction des paragraphes de fin de panneau central
    titre2.setOpaque(false);
    titre2.setEditable(false);
    middle.add(titre2);
    texte2.setOpaque(false);
    texte2.setEditable(false);
    middle.add(texte2);
    titre3.setOpaque(false);
    titre3.setEditable(false);
    middle.add(titre3);
    //construction du panneau intermédiaire inclus dans le panneau central
    JPanel col2 = new JPanel();
    col2.setLayout(new BorderLayout());
    icon3 = new ImageIcon(getClass().getResource("/images/photo.png"),"Liste des étudiants");
    JLabel lbli4 = new JLabel(icon3);
    texte3.setOpaque(false);
    texte3.setEditable(false);
    col2.add(lbli4, BorderLayout.EAST);
    col2.add(texte3, BorderLayout.WEST);
    middle.add(col2);
    titre4.setOpaque(false);
    titre4.setEditable(false);
    middle.add(titre4);
    texte4.setOpaque(false);
    texte4.setEditable(false);
    middle.add(texte4);
    titre5.setOpaque(false);
    titre5.setEditable(false);
    middle.add(titre5);
    texte5.setOpaque(false);
    texte5.setEditable(false);
    middle.add(texte5);
    titre6.setOpaque(false);
    titre6.setEditable(false);
    middle.add(titre6);
    texte6.setOpaque(false);
    texte6.setEditable(false);
    middle.add(texte6);
    titre7.setOpaque(false);
    titre7.setEditable(false);
    middle.add(titre7);
    texte7.setOpaque(false);
    texte7.setEditable(false);
    middle.add(texte7);



    sous_titre = new Color(104,150,255);
    sous_titreComp.add(titre2);
    sous_titreComp.add(titre3);
    sous_titreComp.add(titre4);
    sous_titreComp.add(titre5);
    sous_titreComp.add(titre6);
    sous_titreComp.add(titre7);

    dipScroll = new JScrollPane(middle);
    dipScroll.setBorder(null);
    container.add(top, BorderLayout.NORTH);
    container.add(dipScroll, BorderLayout.CENTER);

    top.setBackground(new Color(255,255,255));
    middle.setBackground(new Color(255,255,255));
    col1.setBackground(new Color(255,255,255));
    col2.setBackground(new Color(255,255,255));

    for(Component c : sous_titreComp){
        c.setFont(new Font("Arial",Font.BOLD,15));
        c.setForeground(sous_titre);
    }
    }



    public void setAscenceur(JScrollBar ascenceur) {
        this.ascenceur = ascenceur;
    }

    public JScrollBar getAscenceur() {
        return ascenceur;
    }
}

非常感谢您的帮助…

关于滚动条中的项目,请呼叫。

关于滚动条中的项目,请呼叫。

这也不起作用,我认为有一些东西阻碍了scrollpane的使用…@user6,如果您创建SSCCE,您可能会发现根本问题,或者至少这里有人能够找到原因。这也不起作用,我认为有一些东西阻止了scrollpane的使用…@user6,如果您创建SSCCE,您可能会找到根本问题,或者至少这里有人能够找到原因。
if(e.getSource()==(this.Departement))
            {

                fenetre3 = new fenetre_departement();
                bas.removeAll();
                container2.removeAll();
                container2 = fenetre3.getContainer();

                bas.add(container2, BorderLayout.NORTH);
                this.setContentPane(container);


            }