Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / September 2004

Tip: Looking for answers? Try searching our database.

Problems with panels and components

Thread view: 
Magna - 01 Sep 2004 17:50 GMT
I have created a small aplication in which I have a frame with a
splitPane, on the left side I have panels which are added on run time.
This looks like a list of Panels.
I want to capture and draw the border of a selected panel as a
component, this component has to be above all others. For now I have
the bounds from the rectangle of each panel but I can't create the
component that draws the borde and permit me to drag it along the
other panels

The procedure I want to do is:

Changing panels positions
--------------------------
- Using mouse events, I am trying to change the position of a selected
panel. The procedure is as follows:
 1. I press the panel I want to move
 2. I capture the bounds of the panel in order to draw a Border
 3. When I drag the mouse I move the Border within the left side of
the     splitPane but the panel I had selected stays still.
 4. When I release the mouse, the panel I had selected change into
Border's position and the other panels are put to a side. The Border
dissapears.

I want to avoid using DnD, is there a way to make a component that
draws the border and can be moved be visible above the other ones???

Thanks
Fred L. Kleinschmidt - 01 Sep 2004 22:23 GMT
> I have created a small aplication in which I have a frame with a
> splitPane, on the left side I have panels which are added on run time.
[quoted text clipped - 23 lines]
>
> Thanks

Sounds like you want to get the GlassPane, make it visible, then draw
and drag a rectangle in the glass pane. On button release, hide the
glass pane and reposition the component based on the coordinates of the
button up event.
Signature

Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94  (206)544-5225

Magna - 09 Sep 2004 20:53 GMT
Hello:
I have a parcial solution for this but without using GlassPane.
In my application I ADD panels in my left side of my Split Pane, I can
add a rectangle component over the selected panel and drag that
rectangle... the problem is when I am releasing the mouse... the panel
did get the new position but I can't make the other panels to reorder
themselves, the panel I moved is over another one... how can I put the
panel in its new place an realign the others??

My application looks like this:
+---------+------------+
|         |JButton(add)|
|         |            |
|---------.            |
|JComponent            |
(Rectangle)            |
|---------.            |
|         |            |
|         |            |
.---------.            |+
|JPanel   |            |
.---------.-------------

I have 3 classes and 1 main class:
- objLegend
- objPanel
- objRectangle

- objMainWindow

/*********this is the code for each class*******////
public class objLegend extends JPanel
{
    public Container container = new Container();
    public objMainWindow mainWindow = null;
    public int intTotalPanels = 0;
    public int intLastIndexPanel = 0;
    private Rectangle rec = null;
       
    public objLegend()
      {
           super(new GridLayout(0,1));
         
           setFocusable(true);
           setAutoscrolls(true);
           container.setLayout(new BoxLayout(container,
BoxLayout.Y_AXIS));
       
           JScrollPane scrollPane = new JScrollPane(container);
           add(scrollPane);
           show();
      }
   
}

public class objRectangle extends JComponent
{
    objPanel panel = null;
    objMainWindow mainWindow;
    Rectangle rec = null;
   
    public objRectangle()
    {   
        setBorder(BorderFactory.createLineBorder(Color.blue));
        setVisible(true);

   }
}

public class objPanel extends JPanel implements MouseListener,
MouseMotionListener
{
     
        JCheckBox objCheck;
       JLabel objLabel;
       public objMainWindow mainWindow = null;
       public int intOrder = 0;
       private static Rectangle rec = null;
       objPanel objP;
       
       public objPanel()
       {
           super(new BorderLayout());
   
           this.addMouseListener(this);
           this.addMouseMotionListener(this);
             
           objCheck = new JCheckBox();
           objCheck.setSelected(true);
   
           objLabel = new JLabel();
           objLabel.setText("Layer");
                   
           this.add(objCheck, BorderLayout.LINE_START);
           this.add(objLabel, BorderLayout.CENTER);
           this.add(objLabel, BorderLayout.SOUTH); //solo para hacer
bulto
         
           setBorder(BorderFactory.createLineBorder(java.awt.Color.black));
           
           this.show(true);
        }
       

       public void setOrder()
       {
           mainWindow.legend.intTotalPanels =  
mainWindow.legend.intTotalPanels + 1;
           this.intOrder = mainWindow.legend.intTotalPanels;
     
       }
       
       public void mousePressed(MouseEvent e)
          {
             //mainWindow.rectangle.hide();
             rec  = e.getComponent().getBounds();
             System.out.println("Pressed on: "+rec+" ");
             mainWindow.rectangle.setBounds(rec.getBounds().x,
rec.getBounds().y, rec.getBounds().width, rec.getBounds().height);
              //mainWindow.rectangle.show();         
            
            
          }
     
         
          public void mouseDragged(MouseEvent e)
          {
                rec  = e.getComponent().getBounds();
                mainWindow.rectangle.setBounds(mainWindow.rectangle.getBounds().x,
e.getY()+ (this.intOrder-1)*this.getHeight()+this.getHeight()/2,
mainWindow.rectangle.getBounds().width,
mainWindow.rectangle.getBounds().height);
              mainWindow.rectangle.show();   
          }
             

          public void mouseReleased(MouseEvent e)
          {
               Component c = mainWindow.getGlassPane();  
               c.hide();
         
               objP = (objPanel)mainWindow.map.get(this.getName());
             objP.setBounds(objP.getBounds().x,mainWindow.rectangle.getBounds().y,objP.getBounds().width,objP.getBounds().height
);
             mainWindow.rectangle.hide();
         
             System.out.println("Location: "+  this.getLocation());
             this.setLocation(mainWindow.rectangle.getLocation());
             

             System.out.println("Released:
"+mainWindow.rectangle.getLocation()+"  "+mainWindow.map.values());
           
             
          }  
         
          public void mouseClicked (MouseEvent e)
          {
              objP = (objPanel)mainWindow.map.get(this.getName());
              System.out.println("objPanel  "+objP.intOrder);
              mainWindow.intOrder = objP.intOrder;
          }
         
          public void mouseExited  (MouseEvent e) {}
          public void mouseMoved   (MouseEvent e) {}
          public void mouseEntered (MouseEvent e) {}

    }

public class objMainWindow extends JFrame implements ActionListener
{
 public static objMainWindow mainWindow = null;
 public JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
 
 public objLegend legend = new objLegend();
 public JPanel objViewer = new JPanel();  
 
 public JTextField textbox1 = new JTextField(20);
 
 public objRectangle rectangle;
 public objPanel panel;

 public HashMap map = new HashMap();
 
 public int intOrder;

   public objMainWindow(String header)
   {
                super(header);
       addWindowListener(new java.awt.event.WindowAdapter() {
           public void windowClosing(java.awt.event.WindowEvent evt)
{
               System.exit(0);
           }
       });
       setBounds( 300, 100, 700, 600 );
       initGUI();
       show();
       mainWindow = this;
       Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
       Dimension windowSize = mainWindow.getSize();
       mainWindow.setLocation(Math.max(0,(screenSize.width -        
windowSize.width)/2),
               Math.max(0,(screenSize.height-windowSize.height)/2));
     
   }

/******more code******/

public void actionPerformed(ActionEvent e) {
       objPanel objPanelI;
       if ("add".equals(e.getActionCommand()))
       {
           panel = new objPanel();           
           panel.mainWindow = this;
           panel.setOrder();
             
           legend.container.add(panel);
           
           legend.intLastIndexPanel = legend.intLastIndexPanel + 1;
           panel.setName("objPanel"+legend.intLastIndexPanel);
           
           map.put(panel.getName(), panel);//
           
           panel.objLabel.setText(panel.getName());

           panel.setSize(new Dimension (130,71));
                                         
           System.out.println("added");
           Rectangle rec = panel.getBounds();
           System.out.println("PANEL: "+rec);
           sp.revalidate();
         
           
       }
   }

/****more code****/

/****more code****/

   public static void main(String[] args) throws Exception
     {
       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
       new objMainWindow("Paneles");
     }

}

/*****the end********************************************************************/

> > I have created a small aplication in which I have a frame with a
> > splitPane, on the left side I have panels which are added on run time.
[quoted text clipped - 28 lines]
> glass pane and reposition the component based on the coordinates of the
> button up event.
Magna - 09 Sep 2004 21:34 GMT
I posted another "Follow up" before with the source code... this is
the missing code for the objMainWindow class:

   private void initGUI() {
     
        JButton boton = new JButton("ADD");
        boton.setActionCommand("add");
        boton.addActionListener(this);
       
        JButton boton2 = new JButton("Get Top");
        boton2.setActionCommand("gettop");
        boton2.addActionListener(this);
       
        JButton boton3 = new JButton("Set Top");
        boton3.setActionCommand("settop");
        boton3.addActionListener(this);
       
        JButton boton4 = new JButton("Remove");
        boton4.setActionCommand("remove");
        boton4.addActionListener(this);
       
        objViewer.add(boton);
        objViewer.add(boton2);
        objViewer.add(boton3);
        objViewer.add(boton4);
        objViewer.add(textbox1);
   
        rectangle = new objRectangle();
        legend.setAutoscrolls(true);
       
        legend.container.add(rectangle);
       
        sp.setTopComponent(legend);
        sp.setBottomComponent(objViewer);
       sp.setDividerLocation(130);
       
       getContentPane().add( sp, BorderLayout.CENTER );
       
       
   }

> > I have created a small aplication in which I have a frame with a
> > splitPane, on the left side I have panels which are added on run time.
[quoted text clipped - 28 lines]
> glass pane and reposition the component based on the coordinates of the
> button up event.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.