Ajouter un commentaire

yanngrenier

Je sais que le mélange n'est pas idéal, mais c'est une demande de mon patron... alors pas de question SVP :) hihihi!

voici un bout de code :

public void initDialog(Component componentToShow)
{
   JDialog dialog = new JDialog();
   JPanel borderPanel = new JPanel();
   TitleBorder border = BorderFactory.createTitleBorder(strTitle);
   borderPanel.setBorder(border);
 
   dialog.setUndecorated(true); 
   dialog.setResizable(false);
   dialog.getContentPane().removeAll();
   dialog.getContentPane().setLayout(TableLayout.createDefaultLayout(FILL_TYPE)); //this is a custom layout
   dialog.getContentPane().add(borderPanel, "1,1");
 
   borderPanel.setLayout(TableLayout.createDefaultLayout(FILL_TYPE));
   borderPanel.add(componentToShow, "1,1");
 
   DialogMouseListener mouseListener = new DialogMouseListener(dialog);
   borderPanel.addMouseMotionListener(mouseListener);
   borderPanel.addMouseListener(mouseListener);
}
 
private static class DialogMouseListener implements MouseMotionListener, MouseListener
{
   private JDialog dialog = null;
   private Point origin = null;
 
   public DialogMouseListener(JDialog objDialog)
   {
      dialog = objDialog;
      origin = new Point();
   }
 
   public void mouseDragged(MouseEvent e)
   {
      Point p = dialog.getLocation();
 
      if (objDialog != null && origin.getY() <= 26) // 26 = TitleBorder Height
      {
         dialog.setLocation(p.x + e.getX() - origin.x, p.y + e.getY() - origin.y);
      }
   }  
 
   public void mousePressed(MouseEvent e)
   {
      origin.x = e.getX();
      origin.y = e.getY();
   }
 
   //other events are empty so not shown here...
}

Filtered HTML

Plain text

CAPTCHA
Cette question permet de vérifier que vous n'êtes pas un robot spammeur :-)
  SSS   L     U   U  FFFF  PPPP  
S L U U F P P
SSS L U U FFF PPPP
S L U U F P
SSSS LLLL UUU F P