Visualizzazione dei risultati da 1 a 5 su 5

Discussione: JtabbedPane

  1. #1

    JtabbedPane

    ciao a tutti ,
    dovrei realizzare un interfaccia grafica con JtabbedPane che aggiunge delle schede quando l'utente clicca un tasto. ogni scheda deve avere la sua JtextArea. per intenderci deve essere concettualmente simile alle schede dei vari browser ovvero che se ne possono aprire un numero illimitato e sono tutte strutturalmente simili. come posso fare?

  2. #2
    tabbedPane.addTab("Tab 1", new JTextArea());

  3. #3
    però se volessi fare riferimento a quella particolare Jtextarea? mi spiego meglio: mettiamo che nella gui c'è un textfield e l'utente scrive delle frasi. come devo fare per far si che la frase scritta nel textfield compaia solo nella textarea della scheda che è selezionata in quel momento lasciando le altre invariate?

  4. #4
    Ti posto un esempio che sicuramente è meglio di mille parole....
    codice:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    
    
    public class TabbedTest extends JFrame
    {
    	private JTextField inputTextField;
    
    
    	private JButton sendButton;
    
    
    	private JButton addButton;
    
    
    	private JTabbedPane tabbedPane;
    
    
    	public TabbedTest()
    	{
    		super("Test");
    		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		this.inputTextField = new JTextField();
    		this.inputTextField.setColumns(20);
    		this.sendButton = new JButton("INVIA");
    		this.sendButton.addActionListener(new ActionListener()
    		{
    
    
    			public void actionPerformed(ActionEvent e)
    			{
    				sendTextToTab();
    			}
    		});
    		this.addButton = new JButton("AGGIUNGI TAB");
    		this.addButton.addActionListener(new ActionListener()
    		{
    
    
    			public void actionPerformed(ActionEvent e)
    			{
    				addNewTab();
    			}
    		});
    		tabbedPane = new JTabbedPane();
    		tabbedPane.addTab("Tab 1", new JTextArea());
    		this.setLayout(new BorderLayout());
    		JPanel topPanel = new JPanel();
    		topPanel.add(inputTextField);
    		topPanel.add(sendButton);
    		topPanel.add(addButton);
    		this.add(topPanel, BorderLayout.NORTH);
    		this.add(tabbedPane);
    		this.setPreferredSize(new Dimension(500, 500));
    		this.pack();
    	}
    
    
    	protected void addNewTab()
    	{
    		this.tabbedPane.addTab("TAB " + (this.tabbedPane.getTabCount() + 1), new JTextArea());
    	}
    
    
    	protected void sendTextToTab()
    	{
    		JTextArea textArea = (JTextArea) this.tabbedPane.getSelectedComponent();
    		textArea.append(this.inputTextField.getText());
    		this.inputTextField.setText("");
    	}
    
    
    	public static void main(String[] args)
    	{
    		SwingUtilities.invokeLater(new Runnable()
    		{
    
    
    			public void run()
    			{
    				TabbedTest test = new TabbedTest();
    				test.setVisible(true);
    			}
    		});
    	}
    }

  5. #5
    mitico! sei perfetto!!
    era proprio quello che mi serviva!
    grazie mille!!!

Tag per questa discussione

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.