I have a JFrame with a JTextArea: by clicking on this TextArea a JPopupMenu appears with two items "Clear" and "Save".
private void jTextArea1MousePressed(java.awt.event.MouseEvent evt) {
jPopupMenu1.setVisible(true);
}
My question is: this popup always appears at position (0,0) but I would like to show pop where mouse is clicked, inside or relative to the TextArea.
I have try setLocation(x,y) but this methods always prompt in a fixed location and it is not what I am seeking for, and it is not available a method such as setLocationRelativeTo(JTextArea());
don't use a mouseListener as trigger to show the popup, instead use the JComponent componentPopupMenu property, like
myTextArea.setComponentPopupMenu(myPopupMenu)
Doing so will show the popup on right click at the mouse position by default. It has the additional benefit of covering keyboard triggered (LAF dependend, F10 on win) popup requests as well.
If for some reason you really need to manually show the popup, the method you're looking for is
myPopup.show(myTextArea, x, y)
Related
I'm using GWT PopupPanel to display a popup above a button when user clicks it.
I am setting popup's position and showing it like so:
panel.setPopupPosition(leftPos, topPos);
panel.show();
However, when I inspect the popup's top value after it shows, I see that it is positions slightly lower than what I assigned it.
The issue may be that setPopupPosition changes the values that are passed in:
// Account for the difference between absolute position and the
// body's positioning context.
left -= Document.get().getBodyOffsetLeft();
top -= Document.get().getBodyOffsetTop();
How can I make sure the GWT PopupPanel's position is exactly the values I gave it? setPopupPosition() seems to really be the only way to set the position, but it does some manipulation (which is unnecessary for my use case) to the positions I pass in.
You can use direct access to popup's DOM element to adjust PopupPanel position. But it should be done after calling show() and before making popup visible. Otherwise, you'll may see some "jump" effects.
Example:
PopupPanel popupPanel = new PopupPanel();
...
// this callback will be called after PopupPanel.show(), but before it is shown
popupPanel.setPopupPositionAndShow(new PositionCallback() {
#Override
public void setPosition(int offsetWidth, int offsetHeight) {
Style style = popupPanel.getElement().getStyle();
style.setLeft(100, Unit.PX);
style.setTop(100, Unit.PX);
}
});
I have a spark List control that shows a side-list on ListEvent.ITEM_ROLL_OVER event. Basicaly it shows the contents of the item you are hovering. I would be also using ListEvent.ITEM_ROLL_OUT to hide it again but I want the user to be able to click on it (the sidelist) too.
So, i use MouseEvent.ROLL_OUT and check the event.relatedObject's id to see where the cursor went. I added an invisible Rectangle overlaying the sidelist that's a bit larger so it gains focus 1st. But it doesn't.
Googling around, I think that the Spark Rectangle cant gain focus as it doesn't implement InteractiveObject. What should I use?
My logic:
protected function listOUT(event:MouseEvent):void
{
var obj:Object = event.relatedObject;
if (obj.id != "focusRect")
{
sidelist.visible = false;
}
}
My struggle is to keep the side-list visible if the user moves the cursor from the main list to the sidelist.
Any other suggestions outside my approach are also welcome.
Update
(image link)
Red are the invisible Buttons
On roll_over select the item in the mainlist, display the sidelist
based on the selecteditem in the mainlist.
Hide the sidelist when there is no item selected in the main list.
Deselect items inthe mainlist if the sidelist loses focus.
Furthermore mx.core.UIComponent is the lightest component that dispatches focus events.
I need to show a popup layer on a scene, creating a semi-transparent background layer that will also prevent touch events propagation. I am using the latest cocos2d-x v. 3.0-alpha-0.
What I want to achieve is a popup layer that fully handles touches (eg. buttons, menu items, scroll views, etc.), laying on a background layer (for design purposes), that covers the current scene. All items in the scene should not respond to touches any more.
Is this achievable using the new EventDispatcher class? I've been able to disable all touches to the main scene, but all instances of MenuItem that live in the scene are still touchable and active.
How can I achieve this? And, also, how can I create a touch listener that prevents all touches to the main scene but not to the popup?
You can disable menu items by setting setDisable property of menuitems to false.
Example
_menuItem->setEnabled(false);
For Layers use setTouchEnabled property
_backGroungLayer->setTouchEnabled(false);
Make sure that popup layer is not child of layer you want to disable.
To disable all items in menus do this
Suppose _menu contain various menuitems.
CCARRAY_FOREACH(_menu->getChildren(), item)
{
item.isEnabled=NO;
}
if you want to disable selected items just give them tags.There is no need to make any list.
I had the same problem and solved it with mm. It was dirty, but it worked:
Create a button using ccui.button.
Set the button size to your screen size.
Add this button as a background to your popup layer.
This will prevent any thing behind it being clicked.
By default, all CCMenu's have a set priority (kCCMenuHandlerPriority = -128) in cocos2d 2.1. So in a class (usually a CCNode descendant) that wants to swallow everything and preempt anything i do like in this dialog sequencer example below :
- (void)onEnter {
backdrop_.visible = self.isBackDropShown;
MPLOG(#"Adding self as a swallower touch delegate, above the rest of the planet.");
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:_dialogTouchPriority swallowsTouches:YES];
for (CCMenu *mn in _menus) {
mn.touchPriotity = _dialogTouchPriority -1 ;
}
[super onEnter];
}
where _dialogTouchPriority is kCCMenuHandlerPriority-1 by default. It will be served before everything 'below'. It is a bad hack (cocos2d internals could be changed and break this), i know , but bullet proof. Use carefully, make certain you only ever have one of these in your scene.
I have a button with a tabIndex. The button contains a textfield.
When I click on the edge of the button and hit tab, the next item is correctly focussed.
But when I click on the textfield (non-editable,not tab-enabled, no tabindex), and then hit tab, it focusses on the first object on the page, even though the parents focusIn function is triggered, in which I'm setting the focus to the parent object:
parentObject:
addEventListener(FocusEvent.FOCUS_IN, focusIn);
private function focusIn(e:FocusEvent):void
{
//shows the child object (a textfield) has the focus
FlashConnect.trace(Main.instance.stage.focus);
//causes this focusIn function to be called again, but only once again, since then the focus does not change anymore
Main.instance.stage.focus = this;
//shows THIS parent object now has the focus
FlashConnect.trace(Main.instance.stage.focus);
//shows the correct tabIndex, which makes me expect the next item should be selected when I hit tab right?
FlashConnect.trace(Main.instance.stage.focus.tabIndex);
}
Any ideas how to solve this?
Have you tried setting mouseEnabled, mouseChildren, and tabChildren? Also, I have to point out that a Singleton View is even more bad practice than other Singletons. You're likely to really regret this architectural choice long term.
I have created a custom TitleWindow whcih i use as a popup. The contents of the popup are created dynamically depending on a selection a user makes from a datagrid.
My problem is, my datagrid is in another custom component whcih is toward the bottom of my page so when a user clicks one of the items the popup is displayed however with half of it out of sight at the bottom of the page.
Is there a way to position a popup so that it displays at the top of the page?
I know at least two things you can use to position a popup, though there might be more.
When you place a popup you can choose in which parent component to place the popup:
PopUpManager.createPopUp(this.parent, TitleWindowComponent);
In the component itself:
PopUpManager.centerPopUp(this);
I wanted a help tooltip type popup (with help text) to appear next to the icon that opened it. In the end I used move(x,y) to move the window where I wanted it. To get the coordinates to place it, use globalToLocal:
var globalX:Number = localToGlobal(new Point(myIcon.x, myIcon.y)).x;
var globalY:Number = localToGlobal(new Point(myIcon.x, myIcon.y)).y;
toolTip.move(globalX + myIcon.width, globalY);
That puts the window just to the right of the icon, myIcon.