Setting Icon for MenuItem
I wanted to set an icon image along with a label in MenuItem(AWT). I am not using swing component (JMenuItem). Could any one advice me how to do this.
Thanks in advance.
As far as I know you can't set an icon in a MenuItem object. MenuItem extends MenuComponent, which extends Object. None of which have a paint or paintComponent method which you can modify. Maybe you can extend MenuItem and create a class with a paintComponent method?
Sorry
Similar Messages
-
How to set icon on MenuItem, but not in JMenuItem?
saleemtol003 wrote:
You are right.It's not possible to set icon on menuItem.
I am talking about SystemTray in which I added PopupMenu with MenuItem.
but I need MenuItem with icon.Is there another way to solve this problem?Nope, just because you're adding a PopupMenu to a TrayIcon does not change the fact that MenuItems cannot have icons. -
Setting icon for the JMenuItem
I am trying to set the Icon for the JMenuItem and not able to do so.
I have the Images directory in the classes which has all the images. Is this the way to give the dir path. When do I give '\' and when do I give '/' or'//' or'\\'? Thanks.
I gave
JMenuItem mnuitmFileNew = new JMenuItem(new ImageIcon("Images//new.jpg"));
and later in Jbinit() method I have this.
mnuitmFileNew.setMnemonic('N');
mnuitmFileNew.setText("New");
mnuitmFileNew.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
mnuitmFileNew_actionPerformed(e);
});Hi,
I'm not sure if you've seen this yet:
http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html
If you still have any questions please post again.
Regards,
Matt
Java Developer Technical Support
Sun Microsystems -
Setting icon for MII version 12.1.x custom action
Hi,
i tryed to set icon image for custom action for MII version 12.1.x but i did not achieve.
How can it be done?
Thanks.Hello,
I have done it in 11.5. This is how I did it in 11.5. (I am hoping that it has not changed in 12.1)
//funciton for specifying icon
public String GetIconPath() {
return "com/path/to/icons/imagename.png";
Store your image file in the following way
com/path/to/icons and name that as imagename.png
There is also a blog on it
/people/rupesh.bajaj/blog/2007/12/04/beginners-guide-to-create-custom-action-block
I hope it helps.
Regards,
Musarrat
Edited by: Musarrat Husain on May 17, 2011 12:18 PM -
Globally setting icon for a file type
I've been using LilyPond a lot recently. The .ly files it saves don't have their own icon, though, they just get the generic document icon. I know that I can manually set an icon for a single file using 'Get Info', but it's not practical now because I have so many .ly files. Is there a way I can tell OS X to use my own icon every time it sees a .ly file?
Thanks,
(- Steve -)Hi, Stephen.
If by LilyPond you mean this application, it's the application's responsibility to assign the custom icon for files it creates, e.g. .ly files you edit and save in LilyPond. You might want to send feedback concerning this to the developers. However, as I understand the application based on a quick review of its manual, it can work with any plain-text (ASCII) file.
You can change the default application in which all .ly files open by using the instructions in "Mac OS X 10.4 Help: Changing the application that opens a document." That may result in those files bearing the same icon as the LilyPond application. That is also the mechanism by which a given icon is assigned to all files of a given type.
Good luck!
Dr. Smoke
Author: Troubleshooting Mac® OS X -
Setting icon for buttons in labview 6i
Hi All,
Currently i am working on Labview 6i. i created two buttons in my vi one button is used to perform the test, another will be used to exit from the test. i would like to add icons for those buttons. can anyone tell me how to add icons for buttons.
Thanks,
kalpanaYou realize that LabVIEW 6.0 is at least 15 years old? That would be almost equivalent to working with a Windows 98 machine nowadays!
Yes your picture can't be imported in LabVIEW 6.0 on my machine either. I haven't checked about all the details, but the LabVIEW import in 6.0 doesn't seem to work for png and gif images but only for bmp. Newer versions do work for your png file including honoring the transparency at least since version 7.1.
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions -
[SOLVED] Set icons for applications in XFCE
Hi,
I was wondering if I can specify the icons for applications. Currently my gVim is using a "general" icon when in the panel but has the right icon when I create a launcher. This is how it looks like. Any suggestions?
Thanks!
Last edited by dsdeiz (2011-01-10 00:50:57)Hi,
Yep, I have a gvim.desktop in /usr/share/applications. What it contains is:
Type=Application
TryExec=gvim
Exec=gvim
Icon=gvim
Terminal=false
Type=Application
TryExec=gvim
Exec=gvim
Icon=gvim
Terminal=false
There is also gvim.png in /usr/share/pixmaps. -
Setting icon for the attachment
Anyone know how to set the icon of the attachment?
I have no problem sending attachment (in this particular case of *.xls files), but the email I received using NOTES shows a default grey box with the correct file. Tried using NOTES to send Excel attachment, and it showed up with a nice icon indicating Excel file. How can I do the same? Thanks in advance.I have had a similar problem and have not been able to determine whether the problem is related to Windows XP Pro, Lotus Notes 5.0.11, or Microsoft Office/OpenOffice. A search of the Internet turned up a number of related issues (attachment icon is missing/invisible, etc).
The Java program I use to email attached files used to work without any problems, but sometime after I moved to an XP workstation, installed Open Office, and applied XP Service Pack 1, the attachment icons (at least for some file types) became invisible. I can't help suspect that the problem lies in XP or Office, but I have not been able to determine that for sure.
FWIW: A suggested workaround (from the Lotus Notes forum) is to change your screen display from 32 colors to 16 colors. This has helped make the attachment icons visible when sending mail from Notes, but it has not helped the Java Mail attachments become any less invisible. Maybe the next step would be to go to a monochrome display? -
I created Icon with Borderpane, image and text which I want to set as button icon.
@Override
public void start(Stage primaryStage)
final VBox vbox = new VBox();
// create 3 toggle buttons and a toogle group for them
ToggleButton tb1 = new ToggleButton();
tb1.setGraphic(newConnectionIcon());
ToggleButton tb2 = new ToggleButton();
ToggleButton tb3 = new ToggleButton();
final ToggleGroup group = new ToggleGroup();
tb1.setToggleGroup(group);
tb2.setToggleGroup(group);
tb3.setToggleGroup(group);
// select the first button to start with
group.selectToggle(tb1);
final Rectangle rect1 = new Rectangle(300, 300);
rect1.setFill(Color.DARKOLIVEGREEN);
final Rectangle rect2 = new Rectangle(300, 300);
rect2.setFill(Color.LAVENDER);
final Rectangle rect3 = new Rectangle(300, 300);
rect3.setFill(Color.LIGHTSLATEGREY);
tb1.setUserData(rect1);
tb2.setUserData(rect2);
tb3.setUserData(rect3);
group.selectedToggleProperty().addListener(new ChangeListener<Toggle>()
@Override
public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle)
if (new_toggle == null)
else
vbox.getChildren().set(1, (Node) group.getSelectedToggle().getUserData());
HBox hBox = new HBox();
hBox.getChildren().addAll(tb1, tb2, tb3);
hBox.setPadding(new Insets(10, 10, 10, 10));
vbox.getChildren().addAll(hBox, (Node) group.getSelectedToggle().getUserData());
StackPane root = new StackPane();
root.getChildren().add(vbox);
Scene scene = new Scene(root, 800, 850);
primaryStage.setScene(scene);
primaryStage.show();
private static BorderPane newConnectionIcon() {
// Add background effect
DropShadow ds = new DropShadow();
ds.setOffsetY(2.0);
ds.setOffsetX(2.0);
ds.setColor(Color.GRAY);
// New BorderPane which will hold the components
bpi = new BorderPane();
bpi.setEffect(ds); // Add the effect
bpi.setCache(true);
// Set the size of the BorderPane
bpi.setPrefSize(30, 30);
bpi.setMaxSize(30, 30);
// Add style
bpi.setStyle("-fx-background-color: linear-gradient(#f2f2f2, #d4d4d4);"
+ " -fx-background-insets: 0 0 -1 0, 0, 1, 2;"
+ " -fx-background-radius: 3px, 3px, 2px, 1px;");
// Add Label to the Icon
Text inftx = new Text("New Connection");
inftx.setFont(Font.font ("Verdana", 5)); // Set font and font size
inftx.setFill(Color.WHITE); // Set font color
ncpic.setFitHeight(25); // Set size of the Icon picture
ncpic.setFitWidth(25);
// Internal StackPane which will hold the picture and the Icon Label
StackPane stack = new StackPane();
stack.getChildren().addAll(ncpic, inftx); // Add the picture and the Label
// Add the StackPane to the main BorderPane
bpi.setCenter(stack);
// Change the border of the Icon when the mouse is over the Icon
bpi = mouseOver(bpi);
// Navigate to new Panel when the user clicks on the Icon
bpi.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
return bpi;
How I can remove the default togglebutton and use the my custom icon as a button?Yes, they are icons and they are called "handles". The easiest way to change then is to use UIManager.
If you haven't done so before, look through the hash table UIManager.getLookAndFeelDefaults().
import java.awt.*;
import java.net.*;
import javax.swing.*;
public class TreeIcons {
public static void main(String[] args) throws MalformedURLException {
String prefix = "http://forum.java.sun.com/images/";
UIManager.put("Tree.openIcon", new ImageIcon(new URL(prefix + "dont_save.gif")));
UIManager.put("Tree.closedIcon", new ImageIcon(new URL(prefix + "save.gif")));
UIManager.put("Tree.leafIcon", new ImageIcon(new URL(prefix + "forum_new.gif")));
UIManager.put("Tree.expandedIcon", new ImageIcon(new URL(prefix + "email_faded.gif")));
UIManager.put("Tree.collapsedIcon", new ImageIcon(new URL(prefix + "email.gif")));
JFrame f = new JFrame("TreeIcons");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new JTree());
f.setSize(new Dimension(300,400));
f.setLocationRelativeTo(null);
f.setVisible(true);
} -
How to set icon for .lnk on PPC
I'm using the Mysaifu JVM and I would like to know how to set an icon of my choice for the shortcut file to my application (.lnk). Currently, the Mysaifu character shows up as the icon.
On a previous post, I found out how to run my java application using the following text in my .lnk file:
255#"\Program Files\Mysaifu JVM\jre\bin\jvm.exe" -Xhidevmwindow -Xmx5M -jar "\My Documents\DeliveryOrganizer.jar" DeliveryOrganizer
Please help!!!
Your help would be much appreciated!
Thanks!I don't think you're going to have much luck modifying the original link, since the jvm.exe is what the link is pointing to. Windows Mobile is getting its icon from the jvm.exe, and not the DeliveryOrganizer jar file.
However, you might look into creating a separate .lnk file, that then calls your original .lnk file that executes the jvm.exe. See if Windows Mobile allows you to modify the new .lnk file's properties... -
hi,
I have a JTree. For this JTree i have a DefaultJTreeCellRenderer.
i have done like this
JTree tree = new JTree();
DefaultJTreeCellRenderer renderer = new DefaultJTreeCellRenderer();
renderer.setOpenIcon(....);
renderer.serCloseIcon(...);
tree.setCellRenderer(renderer);but this is not working.
how to change the icons of the node when i click
thank youpublic class Test extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private JButton buttonCreate;
private JTree tree;
private DefaultMutableTreeNode defaultMutableTreeNode;
private DefaultTreeModel defaultTreeModel;
private int i;
public Test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
layoutComponents();
setSize(400, 400);
setLocationRelativeTo(null);
setVisible(true);
private void layoutComponents() {
defaultMutableTreeNode = new DefaultMutableTreeNode("Root");
defaultTreeModel = new DefaultTreeModel(defaultMutableTreeNode);
tree = new JTree(defaultTreeModel);
tree.setRootVisible(false);
buttonCreate = new JButton("Create");
getContentPane().setLayout(new BorderLayout());
getContentPane().add(tree, BorderLayout.CENTER);
getContentPane().add(buttonCreate, BorderLayout.SOUTH);
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
ImageIcon icon_close = new ImageIcon("./images/project_closed.gif");
ImageIcon icon_open = new ImageIcon("./images/project_opened.gif");
renderer.setOpenIcon(icon_open);
renderer.setClosedIcon(icon_close);
tree.setCellRenderer(renderer);
buttonCreate.addActionListener(this);
public static void main(String[] args) {
new Test();
public void actionPerformed(ActionEvent e) {
addElementToParent("Child" + i++);
private DefaultMutableTreeNode addElementToParent(Object theChild) {
return addElementToParent(defaultMutableTreeNode, theChild, true);
private DefaultMutableTreeNode addElementToParent(DefaultMutableTreeNode theParent, Object theChild, boolean shouldBeVisible) {
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(theChild);
if (theParent == null) {
theParent = defaultMutableTreeNode;
defaultTreeModel.insertNodeInto(childNode, theParent, theParent.getChildCount());
TreePath childTreePath = new TreePath(childNode.getPath());
// Make sure the user can see the lovely new node.
if (shouldBeVisible) {
tree.scrollPathToVisible(childTreePath);
tree.requestFocusInWindow();
return childNode;
}this is the code which i was trying to execute.
here i want to explain you is
when i click the node the icon should change to open_icon
when i click the other node the previous node icon should change to close_icon
how is this possible
null -
Set icon for toggle control of JTree node.
hi.
Just a question.
I am looking towards setting the icons of the JTree by this i mean the icon that you click on
to open say a node .
I know you can set the icons of the nodes by setIcon inside your TreeCellRenderer but i doubt that
that will set the icon that is to the left ot your label.
Has anyone gone down this path recently.
The class BasicTreeUI has a method
called paintExpandControl( Graphics g,
Rectangle clipBounds,
. Insets insets,
Rectangle bounds,
TreePath path,
int row,boolean isExpanded,
boolean hasBeenExpanded,
boolean isLeaf)
Hopefull this is a method that can paint the toggle node so has anyone subclassed BasicTreeUI and done something like this recently.
Any advise on the topic is really appreciated.
Thank you.Yes, they are icons and they are called "handles". The easiest way to change then is to use UIManager.
If you haven't done so before, look through the hash table UIManager.getLookAndFeelDefaults().
import java.awt.*;
import java.net.*;
import javax.swing.*;
public class TreeIcons {
public static void main(String[] args) throws MalformedURLException {
String prefix = "http://forum.java.sun.com/images/";
UIManager.put("Tree.openIcon", new ImageIcon(new URL(prefix + "dont_save.gif")));
UIManager.put("Tree.closedIcon", new ImageIcon(new URL(prefix + "save.gif")));
UIManager.put("Tree.leafIcon", new ImageIcon(new URL(prefix + "forum_new.gif")));
UIManager.put("Tree.expandedIcon", new ImageIcon(new URL(prefix + "email_faded.gif")));
UIManager.put("Tree.collapsedIcon", new ImageIcon(new URL(prefix + "email.gif")));
JFrame f = new JFrame("TreeIcons");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new JTree());
f.setSize(new Dimension(300,400));
f.setLocationRelativeTo(null);
f.setVisible(true);
} -
Setting Color for MenuItem Accelerator Nimbus Layout
Hi,
I'm trying to change the Color for my GUI during runtime. I've created an Dialog including a ColorChooser. If a user selects a new color and confirms the change with "OK" the color of all items in the GUI should be changed. This is working for most of the components.
But the color for the MenuItem Accelerator (f.e. STR+V) does not change. The change for the MenuItem itself is working. I tried different ways - using the UIManager.put, overwriting the MenuItem paint method, but nothing works.
Any ideas or hints?Hi,
I'm trying to change the Color for my GUI during runtime. I've created an Dialog including a ColorChooser. If a user selects a new color and confirms the change with "OK" the color of all items in the GUI should be changed. This is working for most of the components.
But the color for the MenuItem Accelerator (f.e. STR+V) does not change. The change for the MenuItem itself is working. I tried different ways - using the UIManager.put, overwriting the MenuItem paint method, but nothing works.
Any ideas or hints? -
Problem when setting icon for Jframe.....
Hi.....
Iam trying to change the icon of jframe.Iam using the following code.
Toolkit tk = frame.getToolkit();
Image ic = tk.getImage("icons/abc.ico");
frame.setIconImage(ic);
But iam unable to see the icon.In the place of icon empty box is coming.
Any help regarding this will be highly appreciated.
Thanks and Regards,
Kumar.dunno if you can use an ico format, try gif, tif et al
thomas -
How to set different Icons for Jtreenode
How to set different Icons for Jtreenode,i want to set icons for jtreenode,not only for leaf,open,closeicon,i hope that each node has a different icon.Thanks!
you need to check for the node value within a renderer, then assign an icon based on what you expect to get back.
check out this page. http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
Maybe you are looking for
-
Cover flow looks great, and did work, but now shows images of anywhere I've been!. Sometimes just shows white registration lines, and no artwork or images. Any ideas?. Don't understand computers, which is why I've always used a Mac......
-
SQ01 changing signal of a quantity field
Hi I've a query in SQ01 with LIPS table and i need if LIPS-BWART eq '953' , LIPS-LFIMG must be LIPS-LFIMG * (-1) to change signal. Can somebody help me? Thanks
-
Safari not loading Gmail webmail page properly
Safari's not loading the JavaScript version of the Gmail webmail site properly (what Gmail calls the "standard" version, as opposed to the HTML version). When it loads, it shows the lefthand sidebar and top menu bar, but that's it. The rest of the
-
Photoshop document changes to 72 dpi from 300 dpi when receiver opens it.
I created an ad for the newspaper at 300 dpi. I emailed it and received a call it was at a low res of 72. I know I created it and saved it properly. I researched and found I should uncheck the resampling box when saving the document. I did that and r
-
How to install java under suse linux 8.0 prof
hi, first of all, i'm a newbie. i have downloaded the file j2re-1_4_0_01-linux-i586.bin into my public_html directory. which comand do i have to use to install java?? please help! best regards Mad Elk