Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    problemi con layout applet

    sono alle prese con la creazione dell'interfaccia grafica di una applet.
    Nell'applet sono presenti alcune splitbar.
    Il problema è che, appena si avvia l'applet le splitbar sono posizionate in maniera apparentemente casuale:

    Solo ridimensionando l'applet e spostando le splitbar riesco ad ottenere un risultato soddisfacente:


    Vorrei capire come fare a spostare le splitbar da codice.
    Inoltre se non ridimensiono l'applet (quando è in esecuzione) le splitbarverticali non arrivano a coprire tutta l'altezza dell'applet ma si fermano ad un certo punto.
    Spero che dalla prima immagine si riesca a capire quello che intendo dire.


    Questo il codice che ho scritto per disegnare i controlli sull'applet:

    codice:
    public class ChatLayout extends JApplet {
    	private UtentiTableModel utentiModel = new UtentiTableModel();
    	private EffettuateTableModel effettuateModel = new EffettuateTableModel();
    	private RicevuteTableModel ricevuteModel = new RicevuteTableModel();
    	private JTextField txtComando = new JTextField();
    	private JButton cmdInvia = new JButton();
    	private JScrollPane scrSfideEffettuate = new JScrollPane();
    	private JScrollPane scrSfideRicevute = new JScrollPane();
    	private JTable tblSfideEffettuate = new JTable(effettuateModel);
    	private JTable tblSfideRicevute = new JTable(ricevuteModel);
    	private JScrollPane scrChat = new JScrollPane();
    	private JScrollPane scrUtenti = new JScrollPane();
    	private JTable tblUtenti = new JTable(utentiModel);
    	private JButton cmdSfida = new JButton();
    	private CommandHandler handlerButton = new CommandHandler();
    	private String[] tempi = { "1", "2", "3", "5", "10", "15", "20", "30", "60" };
    	private JComboBox cboTempiSfida = new JComboBox(tempi);
    	private String[] colori =  {"bianco", "nero"};
    	private JComboBox cboColore = new JComboBox(colori);
    	private JTextPane txtChat = new JTextPane();
    	private StyledDocument doc = txtChat.getStyledDocument();
    	private ButtonEditor buttonEditor = new ButtonEditor(new JCheckBox());
    	private JPanel pnlChat = new JPanel();
    	private JPanel pnlUtenti = new JPanel();
    	private JSplitPane splitSfide;
    	private JSplitPane splitChat;
    	private JSplitPane splitUtenti;
    	
    	private void Init() throws Exception {
    		GridBagLayout gridbagLayout = new GridBagLayout();
    		GridBagConstraints constraints = new GridBagConstraints();
    		int sp = 5;
    		int defH = 20;
    
    		
    		this.applet.getContentPane().setLayout(gridbagLayout);
    		this.applet.setSize(new Dimension(850, 375));
    		
    		pnlChat.setLayout(gridbagLayout);
    		//pnlChat.setBounds(new Rectangle(sp, sp, defH * 15, defH * 15));
    		pnlChat.setBorder(
    	            BorderFactory.createCompoundBorder(
    	                BorderFactory.createCompoundBorder(
    	                                BorderFactory.createTitledBorder("Chat"),
    	                                BorderFactory.createEmptyBorder(5,5,5,5)),
    	                                pnlChat.getBorder()));
    		//this.applet.getContentPane().add(pnlChat, null);
    		
    		scrChat.getViewport().add(txtChat, null);
    		constraints.anchor = GridBagConstraints.NORTHWEST;
    		constraints.fill = GridBagConstraints.BOTH;
    		setComponent(gridbagLayout, constraints,  scrChat
    				,0 ,0, 2, 1
    				,1000.0, 1000.0 );
    		pnlChat.add(scrChat, null);
    		
    		constraints.anchor = GridBagConstraints.SOUTHWEST;
    		constraints.fill = GridBagConstraints.BOTH;
    		setComponent(gridbagLayout, constraints,  txtComando
    				,0 , 1, 1, 1
    				,1000.0, 0 );
    		pnlChat.add(txtComando, null);
    		
    		constraints.anchor = GridBagConstraints.SOUTHEAST;
    		constraints.fill = GridBagConstraints.BOTH;
    		setComponent(gridbagLayout, constraints,  cmdInvia
    				,1 ,1 ,1 ,1
    				,(double)(sp * 15), 0);
    		pnlChat.add(cmdInvia, null);
    		cmdInvia.setText("Invia");
    		
    		
    		scrSfideEffettuate.setBorder(
    	            BorderFactory.createCompoundBorder(
    	                BorderFactory.createCompoundBorder(
    	                                BorderFactory.createTitledBorder("Sfide effettuate"),
    	                                BorderFactory.createEmptyBorder(5,5,5,5)),
    	                                scrSfideEffettuate.getBorder()));
    		scrSfideEffettuate.getViewport().add(tblSfideEffettuate, null);
    		
    		scrSfideRicevute.setBorder(
    	            BorderFactory.createCompoundBorder(
    	                BorderFactory.createCompoundBorder(
    	                                BorderFactory.createTitledBorder("Sfide ricevute"),
    	                                BorderFactory.createEmptyBorder(5,5,5,5)),
    	                                scrSfideRicevute.getBorder()));
    		scrSfideRicevute.getViewport().add(tblSfideRicevute, null);
    		
    		
    		splitSfide = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
    				scrSfideEffettuate,
    				scrSfideRicevute);
    		splitSfide.setOneTouchExpandable(true);
    		splitSfide.setResizeWeight(0.5);
    		splitSfide.setBounds(new Rectangle(pnlChat.getX() + pnlChat.getWidth() + sp,
    				sp,
    				defH * 15,
    				defH * 15 ));
    		//this.applet.getContentPane().add(splitSfide, null);
    		
    		
    		splitChat = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
    				pnlChat,
    				splitSfide);
    		splitChat.setOneTouchExpandable(true);
    		splitChat.setResizeWeight(0.5);
    		splitChat.setBounds(new Rectangle(sp,
    				sp,
    				splitSfide.getWidth()*2,
    				splitSfide.getHeight() ));
    		//this.applet.getContentPane().add(splitChat, null);
    		
    		
    		
    		
    		pnlUtenti.setLayout(gridbagLayout);
    		pnlUtenti.setBounds(new Rectangle(splitChat.getX() + splitChat.getWidth() + sp
    				, sp, defH * 10, splitChat.getHeight()));
    		pnlUtenti.setBorder(
    	            BorderFactory.createCompoundBorder(
    	                BorderFactory.createCompoundBorder(
    	                                BorderFactory.createTitledBorder("Utenti"),
    	                                BorderFactory.createEmptyBorder(5,5,5,5)),
    	                                pnlUtenti.getBorder()));
    		//this.applet.getContentPane().add(pnlUtenti, null);
    		
    		
    		scrUtenti.getViewport().add(tblUtenti, null);
    		constraints.anchor = GridBagConstraints.NORTHWEST;
    		constraints.fill = GridBagConstraints.BOTH;
    		setComponent(gridbagLayout, constraints,  scrUtenti
    				,0 ,0, 3, 1
    				,1000.0, 1000.0 );
    		pnlUtenti.add(scrUtenti, null);
    		
    		constraints.anchor = GridBagConstraints.SOUTHWEST;
    		constraints.fill = GridBagConstraints.BOTH;
    		setComponent(gridbagLayout, constraints,  cboTempiSfida
    				,0 , 1, 1, 1
    				,(double)(sp * 9), 0 );
    		pnlUtenti.add(cboTempiSfida, null);
    		
    		constraints.anchor = GridBagConstraints.SOUTH;
    		constraints.fill = GridBagConstraints.BOTH;
    		setComponent(gridbagLayout, constraints,  cboColore
    				,1 , 1, 1, 1
    				,(double)(sp*15), 0 );
    		pnlUtenti.add(cboColore, null);
    		
    		constraints.anchor = GridBagConstraints.SOUTHEAST;
    		constraints.fill = GridBagConstraints.BOTH;
    		setComponent(gridbagLayout, constraints,  cmdSfida
    				,2 , 1, 1, 1
    				,(double)(sp*15), 0 );
    		pnlUtenti.add(cmdSfida, null);
    		cmdSfida.setText("Sfida");
    		
    		
    		splitUtenti = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
    				splitChat,
    				pnlUtenti);
    		splitUtenti.setOneTouchExpandable(true);
    		splitUtenti.setResizeWeight(0.5);
    		splitUtenti.setBounds(new Rectangle(sp,
    				sp,
    				splitSfide.getWidth()*3,
    				splitSfide.getHeight() ));
    		
    		constraints.anchor = GridBagConstraints.NORTHWEST;
    		constraints.fill = GridBagConstraints.BOTH;
    		setComponent(gridbagLayout, constraints,  splitUtenti
    				,0 , 0, 1, 1
    				,1000.0, 1000.0 );
    		
    		this.applet.getContentPane().add(splitUtenti, null);
    		
    		
    		splitSfide.setDividerLocation(600);
    		splitUtenti.setDividerLocation(300);
    		splitChat.setDividerLocation(300);
    		
    	}
    }

  2. #2
    nessuna risposta?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.