bonjours,
je vient de faire un programe qui afficher les ligne d'une base de donné dans des jtexfiled mais ils sont nombreux d'ou il faut un scroll pane qui n'a pas marché je les met dans un jpanel jPanel1.add(textField[i], null); mais il ne s'affiche pas mais il saffiche si je met contenPane.add(textField[i], null) dan tous les cas lescroll pane ne marche pas;. voici mon code:
package a;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.SQLException;
import java.sql.*;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2008
* Company:
* @author not attributable
* @version 1.0
*/
public class Frame2 extends JFrame {
JPanel contentPane;
JEditorPane [] textField=null;
JScrollPane jScrollPane1 = new JScrollPane();
JPanel jPanel1 = new JPanel();
//Construct the frame
public Frame2() throws ClassNotFoundException, SQLException {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.setContentPane(contentPane);
this.setSize(new Dimension(756, 779));
this.setState(Frame.NORMAL);
this.setTitle("Module 1");
/* t.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
t.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
formu.setLayout(null);
getContentPane().add(t);
t.getViewport().add(formu, null);
*/
bd b =new bd();
b.connecter();
Statement st = DriverManager.getConnection("jdbc:odbc:u","u","aaaa").createStatement();
ResultSet rs = st.executeQuery("select * from module1");
textField = new JEditorPane[200];
int i=0;
while(rs.next()){
textField[i] = new JEditorPane();
textField[i].setName("aa"+i);
textField[i].setBounds(new Rectangle(12,(30+i*60),800, (50)));
jPanel1.add(textField[i], null);
textField[i].setText(rs.getString(2));
//scrollPane.add(textField[i],null);
i++;
}
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
jScrollPane1.setViewport(null);
jScrollPane1.setViewportBorder(BorderFactory.createLineBorder(Color.black));
jScrollPane1.setDebugGraphicsOptions(0);
jScrollPane1.setDoubleBuffered(true);
jScrollPane1.setMinimumSize(new Dimension(23, 23));
jScrollPane1.setToolTipText("");
jScrollPane1.setVerifyInputWhenFocusTarget(true);
jScrollPane1.setBounds(new Rectangle(7, 10, 732, 746));
jPanel1.setEnabled(false);
jPanel1.setForeground(Color.black);
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setDebugGraphicsOptions(0);
jPanel1.setNextFocusableComponent(jTextField3);
jPanel1.setOpaque(true);
jPanel1.setLayout(null);
jTextField1.setText("jTextField1");
jTextField1.setBounds(new Rectangle(190, 57, 57, 21));
jTextField2.setText("jTextField2");
jTextField2.setBounds(new Rectangle(197, 152, 57, 21));
jTextField3.setText("jTextField3");
jTextField3.setBounds(new Rectangle(194, 264, 57, 21));
jTextField4.setText("jTextField4");
jTextField4.setBounds(new Rectangle(226, 699, 57, 21));
jTextField5.setText("jTextField5");
jTextField5.setBounds(new Rectangle(193, 736, 57, 21));
contentPane.add(jScrollPane1, null);
//jPanel1.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jPanel1, null);
jPanel1.add(jTextField1, null);
jPanel1.add(jTextField2, null);
jPanel1.add(jTextField3, null);
jPanel1.add(jTextField5, null);
jPanel1.add(jTextField4, null);
}
}
Afficher la suite