JDK-4129112 : JToolBar re-floating doesn't work
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.5
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1998-04-15
  • Updated: 1998-06-02
  • Resolved: 1998-06-02
Related Reports
Duplicate :  
Description

Name: rk38400			Date: 04/15/98


I have added a JToolBar in the "North"
of the content pane. It is floatable.

The first time i drag it off, it works. 
Then i close the floating window, and the tollbar 
returns in the "North" of the content pane.

Now it becomes difficult drag it off again.
==============================================

import java.awt.*;  
import java.awt.event.*;
import java.util.*; 
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.text.*;
import com.sun.java.swing.border.*;  

public class FirstAppl extends JFrame 
{
	public static void main(String[] args) 
	{
		try
		{
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
			/*
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.mac.MacLookAndFeel");
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
			*/
		}
		catch (Exception e){}
		
		new FirstAppl("Prove");
	}

	public FirstAppl(String lab) 
	{
		Container content=getContentPane();
		content.setLayout(new BorderLayout());
		ImageScrollPane isp=new ImageScrollPane("tondo.jpg");
		content.add("Center",isp);

		JMenuBar mbar=new JMenuBar();

		JMenu mfile=new JMenu("File");
		JMenu medit=new JMenu("Edit");
		JMenu mproj=new JMenu("Project");
		mbar.add(mfile);
		mbar.add(medit);
		mbar.add(mproj);

		mfile.setToolTipText("File menu");
		medit.setToolTipText("Edit menu");
		mproj.setToolTipText("Project menu");

		JMenuItem mopen=new JMenuItem("Open");

		Icon cane=new ImageIcon(getClass().getResource("cane.gif"));
		JMenuItem mclose=new JMenuItem(cane);
		Icon ape=new ImageIcon(getClass().getResource("ape.gif"));
		JMenuItem mnew=new JMenuItem("New",ape);
		JCheckBoxMenuItem mview=new JCheckBoxMenuItem("Vedi...");

		mnew.setHorizontalTextPosition(AbstractButton.RIGHT);
     	mfile.add(mopen);
		mfile.add(mclose);
		mfile.add(mnew);
		mfile.add(new JSeparator());
		mfile.add(mview);
		mfile.add(new JSeparator());

		ButtonGroup colori=new ButtonGroup();
		JRadioButtonMenuItem scelta1=new JRadioButtonMenuItem("Rosso");
		JRadioButtonMenuItem scelta2=new JRadioButtonMenuItem("Verde");
		JRadioButtonMenuItem scelta3=new JRadioButtonMenuItem("Blu");
		colori.add(scelta1);
		colori.add(scelta2);
		colori.add(scelta3);
		mfile.add(scelta1);
		mfile.add(scelta2);
		mfile.add(scelta3);

		content.add("North",mbar);

		mclose.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{
				doDialog();
			}
		});

		JPopupMenu pm=new JPopupMenu("Comandi");
		JMenuItem m1=new JMenuItem("uno");
		JMenuItem m2=new JMenuItem("due");
		JMenuItem m3=new JMenuItem("tre");
		pm.add(m1);
		pm.add(m2);
		pm.add(m3);

		final Component temp1=isp.getContent();
		final JPopupMenu temp2=pm;
		isp.getContent().addMouseListener(new MouseAdapter(){
			public void mousePressed(MouseEvent me)
			{
				temp2.show(temp1,me.getX(),me.getY());
			}
		});

		JToolBar tb=new JToolBar();
		JButton tb1=new JButton("apri");
		JButton tb2=new JButton("nuovo");
		JButton tb3=new JButton("salva");
		tb.add(tb1);
		tb.add(tb2);
		tb.add(tb3);
		content.add("North",tb);

		setLocation(100,100);
		setSize(400,300);
		show();
	}

	void doDialog() 
	{ 
		final JDialog dlg=new JDialog(this,"Hello",true);
		Container content=dlg.getContentPane();
		content.setLayout(new BorderLayout());

		JLabel lab=new JLabel("porca vacca boia");
		Border offext=new EmptyBorder(5,5,5,5);
		Border line=new CompoundBorder(offext,new EtchedBorder());
		lab.setBorder(new CompoundBorder(line,new EmptyBorder(5,5,5,5)));

		content.add("Center",lab);

		JPanel p=new JPanel();
		content.add("South",p);
		p.setLayout(new FlowLayout(FlowLayout.CENTER));
		JButton ok=new JButton("ok");
		p.add(ok);
		ok.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae){
				dlg.dispose();
			}
		});

		dlg.pack();
		Rectangle s=getBounds();

		dlg.setLocation(s.x+100,s.y+100);
		dlg.show();
	}

	class ImageScrollPane extends JScrollPane
	{
		JLabel lbl;
		ImageScrollPane(String file)
		{
			Icon tondo=new ImageIcon(getClass().getResource("tondo.jpg"));
			lbl=new JLabel(tondo);
			getViewport().add(lbl);
		}

		JComponent getContent(){return lbl;}
	}
}
(Review ID: 27477)
======================================================================

Comments
EVALUATION Jeff, I think I fixed this -- could you check it out? georges.saab@Eng 1998-05-29 This is an AWT bug, # 4035189 which was fixed for 1.1.7. jeff.shapiro@Eng 1998-06-02
29-05-1998