private void setBounds(Point location, Dimension size) { if (myView != null) { if (size == null) { size = myView.getSize(); } if (location == null) { location = myView.getLocation(); } else { Component parent = myView instanceof Window ? null : myView.getParent(); if (parent != null) { SwingUtilities.convertPointFromScreen(location, parent); } } myView.setBounds(location.x, location.y, size.width, size.height); if (myView.isVisible()) { myView.invalidate(); myView.validate(); myView.repaint(); } } }
public void btnChoose_actionPerformed() { // java.awt.Rectangle r = dateField.getBounds(); // Point pOnScreen = dateField.getLocationOnScreen(); java.awt.Rectangle r = Jtext.getBounds(); Point pOnScreen = Jtext.getLocationOnScreen(); Point result = new Point(pOnScreen.x, pOnScreen.y + r.height); Point powner = owner.getLocation(); int offsetX = (pOnScreen.x + width) - (powner.x + owner.getWidth()); int offsetY = (pOnScreen.y + r.height + height) - (powner.y + owner.getHeight()); if (offsetX > 0) { result.x -= offsetX; } if (offsetY > 0) { result.y -= height + r.height; } javax.swing.JDialog dateFrame = new javax.swing.JDialog(); dateFrame.setModal(false); dateFrame.setUndecorated(true); dateFrame.setLocation(result); dateFrame.setSize(width, height); dateFrame.addWindowListener( new WindowAdapter() { // 鍦ㄤ换鎰忕殑闈炴棩鏈熼�夋嫨鍖哄崟鍑伙紝鍒欐棩鏈熼�夋嫨缁勪欢灏嗗彉涓洪潪娲诲姩鐘舵�侊紝鑷姩閲婃斁璧勬簮銆� public void windowDeactivated(WindowEvent e) { javax.swing.JDialog f = (javax.swing.JDialog) e.getSource(); f.dispose(); } }); DatePanel datePanel = new DatePanel(dateFrame, parten); dateFrame.getContentPane().setLayout(new BorderLayout()); dateFrame.getContentPane().add(datePanel); dateFrame.setVisible(true); }
protected void handleExecute() { ImageView view = getSelectedView(); if (view != null) { ColorBarAnnotation cbar = (ColorBarAnnotation) view.getAnnotation(view.getSelectedPlot(), ColorBarAnnotation.ID); if (cbar == null) { cbar = new ColorBarAnnotation(view.getModel()); view.setAnnotation(view.getSelectedPlot(), cbar.getIdentifier(), cbar); } log.finest("retrieved color bar annotation for editing"); ColorBarAnnotationPresenter presenter = new ColorBarAnnotationPresenter(cbar); Container c = JOptionPane.getFrameForComponent(view); final JButton okButton = new JButton("OK"); okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); dialog.dispose(); } }); final JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // view.setAnnotation(safeCopy); // icross.setLinePaint(safeCopy.getLinePaint()); // icross.setLineWidth(safeCopy.getLineWidth()); // icross.setGap(safeCopy.getGap()); // icross.setVisible(safeCopy.isVisible()); dialog.setVisible(false); dialog.dispose(); } }); final JButton applyButton = new JButton("Apply"); dialog = new JDialog(JOptionPane.getFrameForComponent(view)); dialog.setLayout(new BorderLayout()); Point p = c.getLocation(); JPanel mainPanel = new JPanel(); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 8, 15, 8)); mainPanel.setLayout(new BorderLayout()); JPanel buttonPanel = ButtonBarFactory.buildRightAlignedBar(okButton, cancelButton, applyButton); mainPanel.add(presenter.getComponent(), BorderLayout.CENTER); mainPanel.add(buttonPanel, BorderLayout.SOUTH); dialog.add(mainPanel, BorderLayout.CENTER); dialog.pack(); dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); dialog.setLocation( (int) (p.getX() + c.getWidth() / 2f), (int) (p.getY() + c.getHeight() / 2f)); dialog.setVisible(true); } }