Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Swing: placing JMenuItem without LayoutManager  (Read 1627 times)
0 Members and 1 Guest are viewing this topic.
Offline Crest

Senior Newbie




Java games rock!


« Posted 2003-04-21 12:24:25 »

Hi,
I'm really stuck with this: I would like to place JMenuiItems without LayoutManager. My approach was:


JMenuItem jMenuItemZO = new JMenuItem();
ImageIcon image1 = new ImageIcon("d:\\vec25shp\\zoomout_up.png");
           jMenuItemZO.setIcon(image1);

getContentPane().setLayout(null);
jMenuItemZO.setBounds(0, 0, 20, 20);
getContentPane.add(jMenuItemZO);

However, this doesn't seem to work properly: the icon gets disrupted, there's a gap of some 5 pixels on the left border of the icons and it's not displayed fully.

So I really wonder how I could place this component correctly.


thanks,
Crest
Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #1 - Posted 2003-04-21 12:34:50 »

(Disclaimer - I'm not a GUI developer)

Is the icon being cut off because you're setting the bounds of the component too small?

Shouldn't you be adding the JMenuItem to a JMenu on a JMenuBar, then adding that menu bar to the JFrame with setJMenuBar?

Hellomynameis Charlie Dobbie.
Offline Crest

Senior Newbie




Java games rock!


« Reply #2 - Posted 2003-04-21 13:15:45 »

Definately not, as there is a gap of some pixels on the left side of the icon. N.B.: using JButton works, so it must be a problem with JMenuItem.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sma

Junior Devvie





« Reply #3 - Posted 2003-04-21 13:25:51 »

It's not a problem, it's by design. You're not supposed to use JMenuItems outside of menus.  See the private method javax.swing.plaf.basic.BasicMenuItemUI#layoutMenuItem for details. The gap is for displaying an optional check mark IIRC.

.: Truth Until Paradox!
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (295 views)
2018-11-16 13:46:03

hadezbladez (164 views)
2018-11-16 13:41:33

hadezbladez (295 views)
2018-11-16 13:35:35

hadezbladez (75 views)
2018-11-16 13:32:03

EgonOlsen (2156 views)
2018-06-10 19:43:48

EgonOlsen (2183 views)
2018-06-10 19:43:44

EgonOlsen (1370 views)
2018-06-10 19:43:20

DesertCoockie (1987 views)
2018-05-13 18:23:11

nelsongames (1630 views)
2018-04-24 18:15:36

nelsongames (2278 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!