1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| public class essaiNumLignes extends javax.swing.JFrame {
static int i=0;
static int lignesEcrites=1;
/** Creates new form essaiNumLignes */
public essaiNumLignes() {
i=1;
initComponents();
}
////********La c'est Netbeans qui a tout ecrit********
////*** Allez plus bas pour voir mon code ***********
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
TextArea1 = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
jScrollPane1.getVerticalScrollBar().setModel(jScrollPane2.getVerticalScrollBar().getModel());
TextArea2 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jScrollPane1.setBorder(null);
jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
jScrollPane1.setAutoscrolls(true);
jScrollPane1.setWheelScrollingEnabled(false);
TextArea1.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background"));
TextArea1.setColumns(20);
TextArea1.setEditable(false);
TextArea1.setRows(5);
jScrollPane1.setViewportView(TextArea1);
jScrollPane2.setViewport(null);
jScrollPane2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jScrollPane2MouseClicked(evt);
}
});
TextArea2.setColumns(20);
TextArea2.setRows(5);
TextArea2.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
TextArea2KeyReleased(evt);
}
});
jScrollPane2.setViewportView(TextArea2);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 385, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE))
.addContainerGap())
);
pack();
}// </editor-fold>
/////*******************C'est là que ca commence reellement******
private void TextArea2KeyReleased(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode()==10){
int nbrlignes=TextArea2.getLineCount();
if (nbrlignes<lignesEcrites){
TextArea1.setText("");
for(int j=1;j<=nbrlignes;j++){
TextArea1.setText(TextArea1.getText()+j+"\n");
}
}
if (nbrlignes>lignesEcrites){
for(int j=(lignesEcrites+1);j<=nbrlignes;j++){
TextArea1.setText(TextArea1.getText()+j+"\n");
}
}
lignesEcrites=nbrlignes;
TextArea2.requestFocus();
int position = TextArea2.getCaretPosition();
TextArea2.insert("",position); ///J'ai essayé ca pour evenir au haut de mon textArea2, mais ca fct pas
}
}
private void jScrollPane2MouseClicked(java.awt.event.MouseEvent evt) {
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new essaiNumLignes().setVisible(true);
TextArea1.setText(1+"\n");
i++;
}
});
//jScrollPane1.getVerticalScrollBar().setModel(jScrollPane2.getVerticalScrollBar().getModel());
}
// Variables declaration - do not modify
private static javax.swing.JTextArea TextArea1;
private static javax.swing.JTextArea TextArea2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
// End of variables declaration
} |
Partager