Oppure

Loading
22/05/06 20:03
Nophiq
Come e dove posso settare le scrollbars di un JPanel (se è possibile)???
aaa
23/05/06 16:04
Rand
Fai cosi:
- dichiari un pannello JPanel
- dichiari un oggetto di scrolling JScrollPane
- usi questo codice x inserire le barre nel JPanel
      JPanel pannello = new JPanel();
      pannello.setPreferredSize(new Dimension(500, 500));
      JScrollPane barre = new JScrollPane(pannello);
      setContentPane(barre);


:k:
aaa
26/05/06 13:19
Nophiq
Postato originariamente da Rand:
setContentPane(barre);

Ma io devo mettere le scrollbar al pannello non tutto al JFrame.
aaa
28/05/06 13:20
Rand
e allora usa un altro tipo di pannello, chiamato JScrollPane (come il classico JPanel, ma dotato di scrollbar) ;)
aaa
06/08/06 20:32
netarrow
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...)

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
import javax.swing.JScrollPane;
import javax.swing.JComboBox;
import java.awt.GridBagConstraints;
import javax.swing.JSlider;
import javax.swing.JTree;
import javax.swing.JList;
import javax.swing.JLabel;
import javax.swing.JTable;

public class Scroller extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JScrollPane jScrollPane = null;

	private JPanel jPanel = null;

	private JComboBox jComboBox = null;

	private JSlider jSlider = null;

	private JTree jTree = null;

	private JList jList = null;

	private JLabel jLabel = null;

	/**
	 * This is the default constructor
	 */
	public Scroller() {
		super();
		initialize();
	}
	
	public static void main(String args[]) {
		new Scroller();
	}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJPanel());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jLabel = new JLabel();
			jLabel.setText("JLabel");
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.fill = GridBagConstraints.BOTH;
			gridBagConstraints3.weighty = 1.0;
			gridBagConstraints3.weightx = 1.0;
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.fill = GridBagConstraints.BOTH;
			gridBagConstraints2.weighty = 1.0;
			gridBagConstraints2.weightx = 1.0;
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints1.weightx = 1.0;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints.weightx = 1.0;
			jPanel = new JPanel();
			jPanel.setLayout(new GridBagLayout());
			jPanel.add(getJComboBox(), gridBagConstraints);
			jPanel.add(getJSlider(), gridBagConstraints1);
			jPanel.add(getJTree(), gridBagConstraints2);
			jPanel.add(getJList(), gridBagConstraints3);
			jPanel.add(jLabel, new GridBagConstraints());
		}
		return jPanel;
	}

	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();
		}
		return jComboBox;
	}

	/**
	 * This method initializes jSlider	
	 * 	
	 * @return javax.swing.JSlider	
	 */
	private JSlider getJSlider() {
		if (jSlider == null) {
			jSlider = new JSlider();
		}
		return jSlider;
	}

	/**
	 * This method initializes jTree	
	 * 	
	 * @return javax.swing.JTree	
	 */
	private JTree getJTree() {
		if (jTree == null) {
			jTree = new JTree();
		}
		return jTree;
	}

	/**
	 * This method initializes jList	
	 * 	
	 * @return javax.swing.JList	
	 */
	private JList getJList() {
		if (jList == null) {
			jList = new JList();
		}
		return jList;
	}

}


Cmq prova ad aggiungere i componenti direttamente al JScrollPane.

ciao
Ultima modifica effettuata da netarrow 06/08/06 20:37
aaa
07/08/06 0:29
Nophiq
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
aaa
07/08/06 16:57
Nophiq
VAAAAAAAAAAAAAAAAAAAAAAAA
VAAAAAAAAAAAAAAAAAAAAAAAA
Grazie Net!!!!!!!!!!!!!!!

:love:
aaa