X

Geertjan's Blog

  • October 9, 2011

Small NetBeans Visual Library Resize Sample

Geertjan Wielenga
Product Manager

When the mouse is moved over this widget, resize borders appear, and the widget can be resized:

When the mouse moves away from the widget, the resize borders disappear:

setLayout(new BorderLayout());
Scene scene = new Scene();
LayerWidget baseLayer = new LayerWidget(scene);
Widget widget = new Widget(scene);
widget.setBorder(BorderFactory.createLineBorder(1));
widget.setPreferredLocation(new Point(10, 20));
widget.setPreferredBounds(new Rectangle(30, 30));
widget.getActions().addAction(ActionFactory.createResizeAction());
widget.getActions().addAction(ActionFactory.createMoveAction());
WidgetAction hoverAction = ActionFactory.createHoverAction(new TwoStateHoverProvider() {
    @Override
    public void unsetHovering(Widget w) {
        w.setBorder(BorderFactory.createLineBorder(1));
    }
    @Override
    public void setHovering(Widget w) {
        w.setBorder(BorderFactory.createResizeBorder(8, Color.BLACK, false));
    }
});
widget.getActions().addAction(hoverAction);
scene.getActions().addAction(hoverAction);
baseLayer.addChild(widget);
scene.addChild(baseLayer);
add(scene.createView(), BorderLayout.CENTER);

Join the discussion

Comments ( 1 )
  • guest Thursday, February 9, 2012

    getActions().addAction(ActionFactory.createSelectAction(new MyWidgetSelectProvider()));

    getActions().addAction(ActionFactory.createPopupMenuAction(new MyWidgetPopupAction()));

    location = widget.convertLocalToScene(location);

    @Override

    public void select(Widget widget, Point localLocation, boolean invertSelection) {...

    The Visual Library provides PopupMenuAction and the popup shows at the right location.

    I also want to show a popup when the user selects the widget. The problem I'm facing is calculating the exact location when the scroll came from in the diagram and the user scrolled the diagram.

    MouseInfo.getPointerInfo().getLocation() is the only valid solution?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.