Ajuda com JTabbedPane

2 respostas
greg10

Preciso construir uma interface que tenha 3 abas (JTabbedPane) que por sua vez irão exibir informações
para o usuário.

Irei utilizar um Jframe para adicioná-las.

Mas eu nunca utilizai o JTabbedPane, alguem poderia me ajudar colocando um exemplo, ou qualquer outra coisa?

Obrigado

2 Respostas

T

http://java.sun.com/docs/books/tutorial/uiswing/components/tabbedpane.html

PhsPbs

tenho esse codigo espero que ajude, é só copiar e colar que vc irá ter uma idia de como fazer a 3 abas, mas tem um comando que não tenho muita certeza para que serve (UIManager.LookAndFeelInfo), acho que é para controlar os diferentes tipos de telas, qualquer duvida é só perguntar

// SwingPLAF.java

import java.awt.<em>;

import java.awt.event.</em>;

import javax.swing.*;
public class SwingPLAF extends JFrame implements ItemListener {

private JRadioButton rbWin, rbMotif, rbMetal;

private UIManager.LookAndFeelInfo LAF[];

private JTextField tfLAF;
public SwingPLAF() {

LAF = UIManager.getInstalledLookAndFeels();

JTabbedPane tabs = new JTabbedPane();

ImageIcon icon = new ImageIcon(diam-verm.gif);

String nomesLAF[] = new String[LAF.length];

// Menu

JMenuBar mb = new JMenuBar();

JMenu menu = new JMenu(Menu 1);

menu.add(new JMenuItem(Item 1));

menu.add(new JMenuItem(Item 2));

menu.addSeparator();

JMenu subMenu = new JMenu(SubMenu);

subMenu.add(new JMenuItem(SubItem 1));

subMenu.add(new JMenuItem(SubItem 2));

menu.add(subMenu);

mb.add(menu);

menu = new JMenu(Menu 2);

menu.add(new JCheckBoxMenuItem(CheckBox 1));

menu.add(new JCheckBoxMenuItem(CheckBox 2));

menu.addSeparator();

ButtonGroup bg = new ButtonGroup();

for (int i=1; i<4; i++)

bg.add(menu.add(new JRadioButtonMenuItem(RadioButton +i)));

mb.add(menu);

setJMenuBar(mb);

// Aba 1

JPanel p1 = new JPanel(new GridLayout(LAF.length+1,1));

p1.add(new JLabel(”‘Look & Feel disponíveis:));

bg = new ButtonGroup();

JRadioButton rb[] = new JRadioButton[LAF.length];

for (int i=0; i<LAF.length; i++) {

rb[i] = new JRadioButton(nomesLAF[i] = LAF[i].getName());

rb[i].addItemListener(this); rb[i].setActionCommand(""+i);

p1.add(rb[i]); bg.add(rb[i]);

}

JPanel p2 = new JPanel(new FlowLayout(FlowLayout.LEFT));

p2.add(new JLabel(LAF));

p2.add(tfLAF = new JTextField(15));

p2.add(new JButton(Botão));

JPanel p3 = new JPanel(new BorderLayout());

p3.add(p1, Center);

p3.add(p2, South);

tabs.addTab(Aba 1, icon, p3, Seleção do LAF da Aplicação);

// Aba 2

p1 = new JPanel();

p1.add(new JComboBox(nomesLAF));

p3 = new JPanel(new GridLayout(1,2));

p3.add(p1);

p3.add(new JScrollPane(new JList(nomesLAF)));

p1 = new JPanel(new BorderLayout());

p1.add(p3, Center);

p2 = new JPanel(new FlowLayout(FlowLayout.LEFT));

p2.add(new JCheckBox(Primeira opção, true));

p2.add(new JCheckBox(Segunda opção));

p1.add(p2, South);

tabs.addTab(Aba 2, icon, p1, JComboBox, JList e JCheckBox);

// Aba 3

p1 = new JPanel(new BorderLayout());

p2 = new JPanel();

p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));

p2.add(new JButton(new ImageIcon(new16.gif)));

p2.add(new JButton(new ImageIcon(open16.gif)));

p2.add(new JButton(new ImageIcon(save16.gif)));

p1.add(p2, East);

p1.add(new JScrollPane(new JTextArea()), Center);

tabs.addTab(Aba 3, icon, p1, JTextArea e JButton);

getContentPane().add(tabs, Center);

setDefaultCloseOperation(3);

rb[0].doClick();

pack();

}
public void itemStateChanged(ItemEvent e) {

try {

String action = ((JRadioButton)e.getSource()).getActionCommand();

int i = Integer.parseInt(action);

UIManager.setLookAndFeel(LAF[i].getClassName());

SwingUtilities.updateComponentTreeUI(this);

tfLAF.setText(LAF[i].getName());

setTitle(Swing PLAF [+LAF[i].getName()+"]");

} catch (Exception exc) { exc.printStackTrace(); }

}
public static void main(String s[]) {

new SwingPLAF().show();

}

}

:?:

Criado 13 de junho de 2008
Ultima resposta 9 de jul. de 2008
Respostas 2
Participantes 3