No se muestra el Scroll
import javax.swing.*;
import java.lang.String;
import java.lang.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Rectangle;
import java.util.Vector;
import javax.swing.event.*;
import java.util.*;
import java.awt.BorderLayout;
import com.borland.dx.sql.dataset.*;
public class anadir extends JPanel {
JFrame miPadre = new JFrame();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
Vector v = new Vector();
JList jList1 = new JList();
JTextField jTextField1 = new JTextField();
JLabel jLabel3 = new JLabel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel4 = new JLabel();
JTextArea jTextArea1 = new JTextArea();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JScrollPane listScrollPane = new JScrollPane(jList1);
private DefaultListModel listModel;
int contador=0;
QueryDataSet queryDataSet1 = new QueryDataSet();
public anadir(JFrame padre) {
miPadre = padre;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
//anadir anadir1 = new anadir();
}
private void cerrar(){
miPadre.dispose();
}
private void jbInit() throws Exception {
listModel = new DefaultListModel();
/* listModel.addElement("Tono");
listModel.addElement("Yo");
listModel.addElement("tu");
listModel.addElement("Rafa");*/
jList1 = new JList(listModel);
jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList1.setSelectedIndex(0);
jList1.setVisibleRowCount(10);
setLayout(null);
jLabel1.setText("");
jLabel1.setIcon(new ImageIcon("c:/uco.gif"));
jLabel1.setBounds(new Rectangle(40, 22, 144, 68));
jLabel2.setBounds(new Rectangle(245, 30, 209, 54));
jLabel2.setIcon(new ImageIcon("c:/Dibujo.jpg"));
jLabel2.setText("");
jList1.setBackground(Color.white);
jList1.setAutoscrolls(true);
jList1.setBorder(BorderFactory.createLineBorder(Color.black));
jList1.setRequestFocusEnabled(true);
jList1.setToolTipText("");
jList1.setSelectionForeground(Color.black);
jList1.setBounds(new Rectangle(92, 106, 93, 114));
jList1.setVisibleRowCount(5);
jTextField1.setBounds(new Rectangle(209, 123, 181, 25));
jLabel3.setText("Introduzca palabra clave");
jLabel3.setBounds(new Rectangle(242, 97, 180, 19));
jButton1.setBackground(new Color(201, 55, 69));
jButton1.setBounds(new Rectangle(208, 161, 90, 31));
jButton1.setForeground(Color.white);
jButton1.setText("Agregar");
jButton1.addActionListener(new anadir_jButton1_actionAdapter(this));
jButton2.setBackground(new Color(201, 55, 69));
jButton2.setBounds(new Rectangle(300, 161, 90, 31));
jButton2.setForeground(Color.white);
jButton2.setText("Quitar");
jButton2.addActionListener(new anadir_jButton2_actionAdapter(this));
jButton2.setEnabled(false);
jLabel4.setText("Ahora introduzca el nuevo resumen");
jLabel4.setBounds(new Rectangle(147, 230, 204, 26));
jTextArea1.setBorder(BorderFactory.createLineBorder(Color.black));
jTextArea1.setBounds(new Rectangle(47, 254, 406, 91));
jButton3.setBackground(new Color(201, 55, 69));
jButton3.setBounds(new Rectangle(129, 369, 106, 31));
jButton3.setForeground(Color.white);
jButton3.setText("Aceptar");
jButton3.addActionListener(new anadir_jButton3_actionAdapter(this));
jButton4.setBackground(new Color(201, 55, 69));
jButton4.setBounds(new Rectangle(260, 369, 106, 31));
jButton4.setForeground(Color.white);
jButton4.setText("Cancelar");
jButton4.addActionListener(new anadir_jButton4_actionAdapter(this));
this.setBackground(new Color(214, 255, 255));
this.add(jLabel2, null);
this.add(jLabel1, null);
this.add(jLabel3, null);
this.add(jButton2, null);
this.add(jButton1, null);
this.add(jList1, null);
this.add(jLabel4, null);
this.add(jButton4, null);
this.add(jButton3, null);
this.add(jTextArea1, null);
this.add(jTextField1, null);
add(listScrollPane,BorderLayout.CENTER);
//add( new JScrollPane( jList1 ) );
Weno este es el codigo, le quiero poner a la lista jList1 un scroll pero no me lo muestra. No me funciona haciendolo asi. A ver si alguien me puede ayudar.Muchisimas gracias.
import java.lang.String;
import java.lang.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Rectangle;
import java.util.Vector;
import javax.swing.event.*;
import java.util.*;
import java.awt.BorderLayout;
import com.borland.dx.sql.dataset.*;
public class anadir extends JPanel {
JFrame miPadre = new JFrame();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
Vector v = new Vector();
JList jList1 = new JList();
JTextField jTextField1 = new JTextField();
JLabel jLabel3 = new JLabel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel4 = new JLabel();
JTextArea jTextArea1 = new JTextArea();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JScrollPane listScrollPane = new JScrollPane(jList1);
private DefaultListModel listModel;
int contador=0;
QueryDataSet queryDataSet1 = new QueryDataSet();
public anadir(JFrame padre) {
miPadre = padre;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
//anadir anadir1 = new anadir();
}
private void cerrar(){
miPadre.dispose();
}
private void jbInit() throws Exception {
listModel = new DefaultListModel();
/* listModel.addElement("Tono");
listModel.addElement("Yo");
listModel.addElement("tu");
listModel.addElement("Rafa");*/
jList1 = new JList(listModel);
jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList1.setSelectedIndex(0);
jList1.setVisibleRowCount(10);
setLayout(null);
jLabel1.setText("");
jLabel1.setIcon(new ImageIcon("c:/uco.gif"));
jLabel1.setBounds(new Rectangle(40, 22, 144, 68));
jLabel2.setBounds(new Rectangle(245, 30, 209, 54));
jLabel2.setIcon(new ImageIcon("c:/Dibujo.jpg"));
jLabel2.setText("");
jList1.setBackground(Color.white);
jList1.setAutoscrolls(true);
jList1.setBorder(BorderFactory.createLineBorder(Color.black));
jList1.setRequestFocusEnabled(true);
jList1.setToolTipText("");
jList1.setSelectionForeground(Color.black);
jList1.setBounds(new Rectangle(92, 106, 93, 114));
jList1.setVisibleRowCount(5);
jTextField1.setBounds(new Rectangle(209, 123, 181, 25));
jLabel3.setText("Introduzca palabra clave");
jLabel3.setBounds(new Rectangle(242, 97, 180, 19));
jButton1.setBackground(new Color(201, 55, 69));
jButton1.setBounds(new Rectangle(208, 161, 90, 31));
jButton1.setForeground(Color.white);
jButton1.setText("Agregar");
jButton1.addActionListener(new anadir_jButton1_actionAdapter(this));
jButton2.setBackground(new Color(201, 55, 69));
jButton2.setBounds(new Rectangle(300, 161, 90, 31));
jButton2.setForeground(Color.white);
jButton2.setText("Quitar");
jButton2.addActionListener(new anadir_jButton2_actionAdapter(this));
jButton2.setEnabled(false);
jLabel4.setText("Ahora introduzca el nuevo resumen");
jLabel4.setBounds(new Rectangle(147, 230, 204, 26));
jTextArea1.setBorder(BorderFactory.createLineBorder(Color.black));
jTextArea1.setBounds(new Rectangle(47, 254, 406, 91));
jButton3.setBackground(new Color(201, 55, 69));
jButton3.setBounds(new Rectangle(129, 369, 106, 31));
jButton3.setForeground(Color.white);
jButton3.setText("Aceptar");
jButton3.addActionListener(new anadir_jButton3_actionAdapter(this));
jButton4.setBackground(new Color(201, 55, 69));
jButton4.setBounds(new Rectangle(260, 369, 106, 31));
jButton4.setForeground(Color.white);
jButton4.setText("Cancelar");
jButton4.addActionListener(new anadir_jButton4_actionAdapter(this));
this.setBackground(new Color(214, 255, 255));
this.add(jLabel2, null);
this.add(jLabel1, null);
this.add(jLabel3, null);
this.add(jButton2, null);
this.add(jButton1, null);
this.add(jList1, null);
this.add(jLabel4, null);
this.add(jButton4, null);
this.add(jButton3, null);
this.add(jTextArea1, null);
this.add(jTextField1, null);
add(listScrollPane,BorderLayout.CENTER);
//add( new JScrollPane( jList1 ) );
Weno este es el codigo, le quiero poner a la lista jList1 un scroll pero no me lo muestra. No me funciona haciendolo asi. A ver si alguien me puede ayudar.Muchisimas gracias.