JScrollPane



  • hallo,

    ich will zu einem JScrollPane 2 Komponenten addiren

    einfach wenn ich die Balken scrollen sollen all 2 Komponenten

    daraufreagiren

    z.B zwei nebeneinander TexArea

    wie könnte es gehen ???



  • Das ist so nicht möglich. Als Workaround könnte ich dir empfehlen dich mit dem RowHeader von JScrollPane auseinanderzusetzen. Für eine Scrollpane lassen sich nämlich Spalten- und Zeilen-Header vergeben. In deinem Fall also setRowHeaderView mit der zweiten TextArea als Parameter ... versuchen kannst du es ja mal ...



  • Hier ein fehlerhaftes aber lauffähiges Beispiel ...
    [java]/*
    * ScrollPaneRowViewDemo.java
    *
    * Created on 10. April 2003, 10:06
    */

    import java.io.;
    import javax.swing.
    ;
    /**
    *
    * @author Sahin Cengiz
    */
    public class ScrollPaneRowViewDemo extends javax.swing.JFrame {

    /** Creates new form ScrollPaneRowViewDemo */
    public ScrollPaneRowViewDemo() {
    initComponents();
    StringBuffer sbuf = new StringBuffer();

    int countLines = 0;
    java.io.File theFile = null;
    BufferedReader br = null;
    String zeile;
    try {
    JFileChooser jfc = new JFileChooser();
    jfc.showOpenDialog(this);
    theFile = jfc.getSelectedFile();
    br = new BufferedReader(new FileReader(theFile));
    zeile=br.readLine();
    while ( zeile != null ) {
    countLines++;
    zeile=br.readLine();
    sbuf.append(zeile);
    }
    jTextPane1.setText(sbuf.toString());
    } catch (IOException ioex) {
    ioex.printStackTrace();
    }
    javax.swing.JTextPane lineNumberPanel = new javax.swing.JTextPane();
    StringBuffer lineBuffer = new StringBuffer();
    for (int i=1; i<countLines; ++i)
    lineBuffer.append(""+i+"\n");
    lineNumberPanel.setMinimumSize(new java.awt.Dimension(50, 200));
    //lineNumberPanel.setPreferredSize(new java.awt.Dimension(50, 200));
    lineNumberPanel.setBackground(java.awt.Color.yellow);
    lineNumberPanel.setAlignmentX(JTextPane.RIGHT_ALIGNMENT);
    lineNumberPanel.setText(lineBuffer.toString());

    jScrollPane1.setRowHeaderView(lineNumberPanel);
    }

    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
    private void initComponents() {
    jPanel1 = new javax.swing.JPanel();
    jPanel2 = new javax.swing.JPanel();
    jPanel3 = new javax.swing.JPanel();
    jPanel4 = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextPane1 = new javax.swing.JTextPane();

    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    }
    });

    getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

    getContentPane().add(jPanel2, java.awt.BorderLayout.EAST);

    getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);

    getContentPane().add(jPanel4, java.awt.BorderLayout.WEST);

    jScrollPane1.setViewportView(jTextPane1);

    getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

    pack();
    }

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
    System.exit(0);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    new ScrollPaneRowViewDemo().show();
    }

    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration
    }[/code]


Anmelden zum Antworten