Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - JPanel con ScrollBars
Forum - Java - JPanel con ScrollBars

Avatar
Nophiq (Founder Member)
Expert


Messaggi: 537
Iscritto: 15/11/2004

Segnala al moderatore
Postato alle 22:03
Lunedì, 22/05/2006
Come e dove posso settare le scrollbars di un JPanel (se è possibile)???

PM Quote
Avatar
Rand (Ex-Member)
Pro


Messaggi: 163
Iscritto: 17/05/2005

Segnala al moderatore
Postato alle 18:04
Martedì, 23/05/2006
Fai cosi:
- dichiari un pannello JPanel
- dichiari un oggetto di scrolling JScrollPane
- usi questo codice x inserire le barre nel JPanel
Codice sorgente - presumibilmente Java

  1. JPanel pannello = new JPanel();
  2.       pannello.setPreferredSize(new Dimension(500, 500));
  3.       JScrollPane barre = new JScrollPane(pannello);
  4.       setContentPane(barre);



:k:

PM Quote
Avatar
Nophiq (Founder Member)
Expert


Messaggi: 537
Iscritto: 15/11/2004

Segnala al moderatore
Postato alle 15:19
Venerdì, 26/05/2006
Testo quotato

Postato originariamente da Rand:
Codice sorgente - presumibilmente Plain Text

  1. setContentPane(barre);



Ma io devo mettere le scrollbar al pannello non tutto al JFrame.

PM Quote
Avatar
Rand (Ex-Member)
Pro


Messaggi: 163
Iscritto: 17/05/2005

Segnala al moderatore
Postato alle 15:20
Domenica, 28/05/2006
e allora usa un altro tipo di pannello, chiamato JScrollPane (come il classico JPanel, ma dotato di scrollbar) ;)

PM Quote
Avatar
netarrow (Admin)
Guru^2


Messaggi: 2502
Iscritto: 12/05/2004

Segnala al moderatore
Postato alle 22:32
Domenica, 06/08/2006
come mi hai chiesto su MSN ho provato a creare ciò che ti serve con il VE di eclipse, ti mostro il codice generato(non ho cambiato i nomi, ho lasciato i soliti jpanell1 ecc...)

Codice sorgente - presumibilmente Java

  1. import java.awt.BorderLayout;
  2. import javax.swing.JPanel;
  3. import javax.swing.JFrame;
  4. import java.awt.GridBagLayout;
  5. import javax.swing.JScrollPane;
  6. import javax.swing.JComboBox;
  7. import java.awt.GridBagConstraints;
  8. import javax.swing.JSlider;
  9. import javax.swing.JTree;
  10. import javax.swing.JList;
  11. import javax.swing.JLabel;
  12. import javax.swing.JTable;
  13.  
  14. public class Scroller extends JFrame {
  15.  
  16.         private static final long serialVersionUID = 1L;
  17.  
  18.         private JPanel jContentPane = null;
  19.  
  20.         private JScrollPane jScrollPane = null;
  21.  
  22.         private JPanel jPanel = null;
  23.  
  24.         private JComboBox jComboBox = null;
  25.  
  26.         private JSlider jSlider = null;
  27.  
  28.         private JTree jTree = null;
  29.  
  30.         private JList jList = null;
  31.  
  32.         private JLabel jLabel = null;
  33.  
  34.         /**
  35.          * This is the default constructor
  36.          */
  37.         public Scroller() {
  38.                 super();
  39.                 initialize();
  40.         }
  41.        
  42.         public static void main(String args[]) {
  43.                 new Scroller();
  44.         }
  45.         /**
  46.          * This method initializes this
  47.          *
  48.          * @return void
  49.          */
  50.         private void initialize() {
  51.                 this.setSize(300, 200);
  52.                 this.setContentPane(getJContentPane());
  53.                 this.setTitle("JFrame");
  54.         }
  55.  
  56.         /**
  57.          * This method initializes jContentPane
  58.          *
  59.          * @return javax.swing.JPanel
  60.          */
  61.         private JPanel getJContentPane() {
  62.                 if (jContentPane == null) {
  63.                         jContentPane = new JPanel();
  64.                         jContentPane.setLayout(new BorderLayout());
  65.                         jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
  66.                 }
  67.                 return jContentPane;
  68.         }
  69.  
  70.         /**
  71.          * This method initializes jScrollPane 
  72.          *      
  73.          * @return javax.swing.JScrollPane     
  74.          */
  75.         private JScrollPane getJScrollPane() {
  76.                 if (jScrollPane == null) {
  77.                         jScrollPane = new JScrollPane();
  78.                         jScrollPane.setViewportView(getJPanel());
  79.                 }
  80.                 return jScrollPane;
  81.         }
  82.  
  83.         /**
  84.          * This method initializes jPanel      
  85.          *      
  86.          * @return javax.swing.JPanel  
  87.          */
  88.         private JPanel getJPanel() {
  89.                 if (jPanel == null) {
  90.                         jLabel = new JLabel();
  91.                         jLabel.setText("JLabel");
  92.                         GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
  93.                         gridBagConstraints3.fill = GridBagConstraints.BOTH;
  94.                         gridBagConstraints3.weighty = 1.0;
  95.                         gridBagConstraints3.weightx = 1.0;
  96.                         GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
  97.                         gridBagConstraints2.fill = GridBagConstraints.BOTH;
  98.                         gridBagConstraints2.weighty = 1.0;
  99.                         gridBagConstraints2.weightx = 1.0;
  100.                         GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
  101.                         gridBagConstraints1.fill = GridBagConstraints.VERTICAL;
  102.                         gridBagConstraints1.weightx = 1.0;
  103.                         GridBagConstraints gridBagConstraints = new GridBagConstraints();
  104.                         gridBagConstraints.fill = GridBagConstraints.VERTICAL;
  105.                         gridBagConstraints.weightx = 1.0;
  106.                         jPanel = new JPanel();
  107.                         jPanel.setLayout(new GridBagLayout());
  108.                         jPanel.add(getJComboBox(), gridBagConstraints);
  109.                         jPanel.add(getJSlider(), gridBagConstraints1);
  110.                         jPanel.add(getJTree(), gridBagConstraints2);
  111.                         jPanel.add(getJList(), gridBagConstraints3);
  112.                         jPanel.add(jLabel, new GridBagConstraints());
  113.                 }
  114.                 return jPanel;
  115.         }
  116.  
  117.         /**
  118.          * This method initializes jComboBox   
  119.          *      
  120.          * @return javax.swing.JComboBox       
  121.          */
  122.         private JComboBox getJComboBox() {
  123.                 if (jComboBox == null) {
  124.                         jComboBox = new JComboBox();
  125.                 }
  126.                 return jComboBox;
  127.         }
  128.  
  129.         /**
  130.          * This method initializes jSlider     
  131.          *      
  132.          * @return javax.swing.JSlider 
  133.          */
  134.         private JSlider getJSlider() {
  135.                 if (jSlider == null) {
  136.                         jSlider = new JSlider();
  137.                 }
  138.                 return jSlider;
  139.         }
  140.  
  141.         /**
  142.          * This method initializes jTree       
  143.          *      
  144.          * @return javax.swing.JTree   
  145.          */
  146.         private JTree getJTree() {
  147.                 if (jTree == null) {
  148.                         jTree = new JTree();
  149.                 }
  150.                 return jTree;
  151.         }
  152.  
  153.         /**
  154.          * This method initializes jList       
  155.          *      
  156.          * @return javax.swing.JList   
  157.          */
  158.         private JList getJList() {
  159.                 if (jList == null) {
  160.                         jList = new JList();
  161.                 }
  162.                 return jList;
  163.         }
  164.  
  165. }



Cmq prova ad aggiungere i componenti direttamente al JScrollPane.

ciao

Ultima modifica effettuata da netarrow il 06/08/2006 alle 22:37
PM Quote
Avatar
Nophiq (Founder Member)
Expert


Messaggi: 537
Iscritto: 15/11/2004

Segnala al moderatore
Postato alle 2:29
Lunedì, 07/08/2006
NO, nessun risultato positivo, il problema è il setSize() del frame, perchè è quello a tener più piccolo la finestra del componente.

Comunque domani provo a guardare perchè ci sono divesi Livelli e quello superiore al ContentPane è il LayoutPane. Eventualmente aggiungere due frame a questo contenitore. Speriamo.

Ciao e grazie net per l'aiuto

PM Quote
Avatar
Nophiq (Founder Member)
Expert


Messaggi: 537
Iscritto: 15/11/2004

Segnala al moderatore
Postato alle 18:57
Lunedì, 07/08/2006
VAAAAAAAAAAAAAAAAAAAAAAAA
VAAAAAAAAAAAAAAAAAAAAAAAA
Grazie Net!!!!!!!!!!!!!!!

:love:

PM Quote