Aplicações MDI

3 respostas
VantuilJose

Alguém tem o código fonte de uma aplicação java que usa um MDI com JInternalFrame, JDesktop e ToolBar?

O Frame interno e o JDesktop eu consigo usar, embora as vezes dê ums probleminhas…
Tô apanhando d+ da ToolBar, se alguém puder me ajudar… :smiley:

3 Respostas

gqferreira

Olá, veja se isto pode te ajudar:

package exemplosGuj;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSeparator;
import javax.swing.JToolBar;
import javax.swing.WindowConstants;

@SuppressWarnings("serial")
public class MDI extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JDesktopPane jdpDesktopPane;
	private JMenu meMenu;
	private JButton btShowInternalFrame;
	private JToolBar jToolBar;
	private JSeparator jSeparator;
	private JRadioButtonMenuItem rbmiRadioButtonMenuItem1;
	private JMenuItem miMenuItem;
	private JCheckBoxMenuItem jcbmiCheckBoxMenuItem;
	private JMenuBar mbBarraDeMenus;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(String[] args) {

		MDI inst = new MDI();
		inst.setLocationRelativeTo(null);
		inst.setVisible(true);
	}


	public MDI() {
		try {
			setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			{
				jdpDesktopPane = new JDesktopPane();
				getContentPane().add(jdpDesktopPane, BorderLayout.CENTER);
				jdpDesktopPane.setPreferredSize(new java.awt.Dimension(638, 468));
				{
					jToolBar = new JToolBar();
					jdpDesktopPane.add(jToolBar);
					jToolBar.setBounds(12, 340, 610, 37);
					{
						btShowInternalFrame = new JButton();
						jToolBar.add(btShowInternalFrame);
						btShowInternalFrame.setText("Show Internal Frame");
						btShowInternalFrame.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								InternalFrame i = new InternalFrame();
								jdpDesktopPane.add(i);
								i.setVisible(true);
								try
								{
									i.setSelected(true);
								}
								catch(Exception ex)
								{
									ex.printStackTrace();
								}

							}
						});
					}
				}
			}
			{
				mbBarraDeMenus = new JMenuBar();
				setJMenuBar(mbBarraDeMenus);
				{
					meMenu = new JMenu();
					mbBarraDeMenus.add(meMenu);
					meMenu.setText("Menu");
					{
						jcbmiCheckBoxMenuItem = new JCheckBoxMenuItem();
						meMenu.add(jcbmiCheckBoxMenuItem);
						jcbmiCheckBoxMenuItem.setText("CheckBoxMenuItem");
					}
					{
						miMenuItem = new JMenuItem();
						meMenu.add(miMenuItem);
						miMenuItem.setText("MenuItem");
						{
							jSeparator = new JSeparator();
							miMenuItem.add(jSeparator);
						}
					}
					{
						rbmiRadioButtonMenuItem1 = new JRadioButtonMenuItem();
						meMenu.add(rbmiRadioButtonMenuItem1);
						rbmiRadioButtonMenuItem1.setText("RadioButtonMenuItem");
					}
				}
			}

			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

InternalFrame:

package exemplosGuj;
import java.awt.FlowLayout;
import javax.swing.JLabel;

@SuppressWarnings("serial")
public class InternalFrame extends javax.swing.JInternalFrame {
	private JLabel lbJava;

	public InternalFrame() {
		try {

			FlowLayout thisLayout = new FlowLayout();
			getContentPane().setLayout(thisLayout);
			this.setBounds(0, 0, 431, 349);
			this.setPreferredSize(new java.awt.Dimension(431, 349));
			this.setClosable(true);
			{
				lbJava = new JLabel();
				getContentPane().add(lbJava);
				lbJava.setText("JAVA");
				lbJava.setFont(new java.awt.Font("AlArabiya",1,72));
				lbJava.setPreferredSize(new java.awt.Dimension(204, 319));
			}

			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
VantuilJose

Ajudou um pouco.
Mas o que eu realmente queria era que a barra de ferramentas ficasse no topo, logo abaixo dos menus.

Alguém sabe se um gerenciador de layout pode me ajudar? em caso afirmativo, como?

S

Olá amigo

usa este framework Open Swing é muito bom:

Já tem um monte coisa pronta para vc usar.

Silvio Guedes

Criado 4 de setembro de 2009
Ultima resposta 9 de set. de 2009
Respostas 3
Participantes 3