Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (746)
Games in Android Showcase (226)
games submitted by our members
Games in WIP (827)
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 1493 times)
0 Members and 1 Guest are viewing this topic.
Offline Crest

Senior Newbie

Java games rock!

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

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.setBounds(0, 0, 20, 20);

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.

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  

xxMrPHDxx (70 views)
2017-12-31 17:17:51

xxMrPHDxx (35 views)
2017-12-31 17:15:51

xxMrPHDxx (41 views)
2017-12-28 18:11:33

Ecumene (212 views)
2017-09-30 02:57:34

theagentd (310 views)
2017-09-26 18:23:31

cybrmynd (356 views)
2017-08-02 12:28:51

cybrmynd (399 views)
2017-08-02 12:19:43

cybrmynd (367 views)
2017-08-02 12:18:09

Sralse (335 views)
2017-07-25 17:13:48

Archive (1083 views)
2017-04-27 17:45:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!