Resize Options Menu entries - java

How could I resize menu entries to have, for example, only one entry on the bottom row. Here is an example:
Notice how the "Add" and "Wallpaper" are both on the top and the others are on the bottom. How could I accomplish the same feat, but having just one menu entry on the bottom and two on the top?

I don't think this is possible, looking at the documentation there are no methods for Menu or MenuItem which would allow you to specify this kind of thing. In your supplied image Add and Wallpaper are listed first (you can specify the order of your menu items) and when there are 5 clearly Android automatically puts 2 on the top and 3 on the bottom.

Related

When i click a button i would like to activate only its surrounding buttons. How is this possible?

I have an 8 by 8 linear Layout of buttons. I am making a small game similar to boggle, when i click a button i would like to be able to disable all buttons except for its surrounding buttons. This also involves the buttons on the edge. I basically need some help to start the logic of this game. any help is appreciated. i have so far thought about the structure of the program and how an 8 by 8 graph can possibly activate its neighbors, maybe if i can access the cell of each button the i can progress further?. Thank you.
Extend Button and give Buttonlisteners to each of the buttons according to who their neighbors are. Each button would have a buttonlistener tied to each of it's neighbors according to how you tie it together. If you don't want to use diagonal neighbors, a button would have a max of 5 buttonlisteners (if the button is listening to it's own button).)
This should be possible to accomplish using a simple Map:
Map<Button, List<Button>> surroundingButtons = new HashMap<Button, List<Button>>();
This Map is then, for each Button, populated with a list of it's surrounding Buttons. Unfortunately I have no clever idea how to do this easily at this hour.
I am thinking something like adding all buttons to a single list and pick them out using index of the current button +/- 8 modulo some index... Adding them manually might be just as easy.
When the Map is ready, it is very simple to disable the surrounding Buttons.
Button clickedButton; // not showing the onClickListener
for (Button sButton: surroundingButtons.get(clickedButton)) {
sButton.setEnabled(false);
}
Edit:
Read the question wrong but; disable all buttons except for its surrounding buttons
The idea still applies, just add all the buttons you wish to disable to the list associated with a button in the map.

How to add an image while we drag n drop tree item?

I have a tree with number of childs and i want to drag and drop these child items on a vertical panel. Right now its working fine.The only thing i want to know is can we add an image in the place of small icon which comes at the time of dragNdrop.
You need to override the newDragProxy() method of the PickupDragController in order to provide your own proxy widget (say, an image) when the drag starts.
Do note that you also need to use setBehaviorDragProxy(true) to allow dragging proxies instead of the original widgets (i.e., the original widgets will stay in place, and you simply drag a proxy of it, that you can style as you wish).

JRadioButtonMenuItem with a tick

I am wondering if it's possible to change the default radio button menu item appearance in Java Swing.
By default a circle with a dot inside will indicate the selected state of the button, but i just want the good old fashioned tick next to a selected menu item and nothing to be shown next to an item that is not selected. (All items in question are of type JRadioButtonMenuItem)
I tried to use .setSelectedIcon(...) which can be found here :
http://docs.oracle.com/javase/7/docs/api/javax/swing/AbstractButton.html#setSelectedIcon(javax.swing.Icon)
But nothing changed, no exceptions thrown and im still stuck with the default appearance.
Any ideas?
Instead of using a JRadioButtonMenuItem, you could use JCheckBoxMenuItem which has a tick mark by default. JCheckBoxMenuItems can also belong to a ButtonGroup also giving you single selection behavior shown by JRadioButtonMenuItem.
Example

Add icon button beside tree item in eclipse tree

I wonder how to add an icon that acts as a button in the right side of a tree item
the selection of this icon should have different action than selecting the tree item itself.
How can I do that?
Example:
consider this is the main tree
http://www.eclipse.org/articles/Article-TreeViewer/images/main.gif
and I want to add icons to the right side of some tree items' label
like
http://store2.up-00.com/June12/8QI59630.gif
just as when I click on the black star icon, I make a different action than selecting the tree item
Such facility does not exist in the tree widget, but you can implement this yourself using a technique called owner-draw where you take over the painting of tree items. See OwnerDrawLabelProvider. To respond to clicks you will need to listen to mouse down even and check whether the coordinates match the bounds of your button before invoking your action.

Changing style of context menu in Android

In one Android activity I have added a context menu to an ImageView with only one menu item: 'Close' (in order to hide the image).
However, the context menu does not look precisely nice when shown, expanding a big white rectangle occupying almost all the wide of the screen. Is there a way to reduce the size of this rectangle to cover only the word 'Close'?. This is my main question, but any pointer to how to change other styles of the context menu will be appreciated (e.g., the background color, or the text font/color). Thanks !
I don't think it's possible to set the menu item width.
However, you can find a great article here that shows how to customize the look of your menu item.

Categories