JMenuItem justification

how can I change JMenuItem justification from right to left, because if I create JMenu with glue then JMenuItem sticking out of the JFrame
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
public class MenuGlueDemo {
    public JMenuBar createMenuBar() {
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(createMenu("Menu 1"));
        menuBar.add(createMenu("Menu 2"));
        menuBar.add(Box.createHorizontalGlue());
        menuBar.add(createMenu("Menu 3"));
        return menuBar;
    public JMenu createMenu(String title) {
        JMenu m = new JMenu(title);
        m.add("Menu item #1 in " + title);
        m.add("Menu item #2 in " + title);
        m.add("Menu item #3 in " + title);
        return m;
    private static void createAndShowGUI() {
        JFrame frame = new JFrame("MenuGlueDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        MenuGlueDemo demo = new MenuGlueDemo();
        frame.setContentPane(demo.createMenuBar());
        frame.setSize(300, 100);
        frame.setVisible(true);
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                createAndShowGUI();
}

How about using the setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT) method.
import java.awt.*;
import javax.swing.*;
public class MenuGlueDemo2 {
  public JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(createMenu("Menu 1"));
    menuBar.add(createMenu("Menu 2"));
    menuBar.add(Box.createHorizontalGlue());
    JMenu menu = createMenu("Menu 3");
    menu.setComponentOrientation(
        ComponentOrientation.RIGHT_TO_LEFT);
    menuBar.add(menu);
    return menuBar;
  public JMenu createMenu(String title) {
    JMenu m = new JMenu(title);
    m.add("Menu item #1 in " + title);
    m.add("Menu item #2 in " + title);
    m.add("Menu item #3 in " + title);
    return m;
  private static void createAndShowGUI() {
    JFrame frame = new JFrame("MenuGlueDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(new MenuGlueDemo2().createMenuBar());
    frame.setSize(300, 100);
    frame.setVisible(true);
  public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      @Override public void run() { createAndShowGUI(); }
}

Similar Messages

  • Disabled JMenuItem doesn show animated gif

    Hi there
    I would like to have a popup menu with actions that are enabled after they have finished with some background task taking some time. Basically this works fine for the enabling action on a shown popup. However, adding an animated gif as the icon or disabled icon does not show it in disabled state. In enabled state it works perfect. Please have a try with the sample code. You should see the disabled item for 2 secs and the icon is not showing up. After being enabled, it does. Invoking the menu again shows the animated gif in its last state left, but not moving any more.
    I guess, repaints are not done appropriately in disabled state... Any ideas how to solve that would be highly appreciated :-)
    Actually I used the icon at http://mentalized.net/activity-indicators/indicators/pascal_germroth/indicator.white.gif
    Cheers
    Daniel
    public class Main
      public static void main(String[] args)
        final JFrame frame = new JFrame();
        frame.addMouseListener(new MouseAdapter()
          public void mousePressed(final MouseEvent e)
            final JPopupMenu popup = new JPopupMenu();
            popup.add(new JMenuItem("Open..."));
            popup.add(new JMenuItem("Close"));
            final JMenuItem action = new JMenuItem("Long loading until enabled");
            action.setIcon(new ImageIcon("C:/spinner.gif"));
            action.setDisabledIcon(new ImageIcon("C:/spinner.gif"));
            popup.add(action).setEnabled(false);
            popup.show(e.getComponent(), e.getX(), e.getY());
            SwingUtilities.invokeLater(new Runnable()
              public void run()
                try
                  Thread.sleep(2000);
                  action.setEnabled(true);
                catch (InterruptedException e1)
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 200);
        frame.setVisible(true);
    }Edited by: daniel.frey on Apr 22, 2009 7:50 AM

    The problem is that you are causing the EDT to sleep, which means the GUI can't repaint itself. Read the section from the Swing tutorial on Concurrency to understand what is happening.

  • Text box Vertical Justification greyed out in CS4

    Does anyone know why the ability to vertically justify my text boxes is disabled?  It is only in this one document (although, I think I remember this occurring in another).  The option is greyed out in the Text Frame Options window and will not allow me to click on the options in the tool bar.  This is rather frustrating and can't for the life of me figure out how to fix it.  Anyone else experience this or know how to fix it?
    Thanks,
    Mel

    Prior to CS5 you can't vertically justify any frame in which the text area is not rectangular. Not only can text wrap change the shape of a text area, but so can corner effects  (adding enough inset will get past this), and of course the use of non-rectangular frames.
    Thanks, Peter.  I had already adjusted the top inset enough to achieve the look I was looking for.  That's good to know about the corner effects.  That is actually when I experienced this before and used insets to achieve my desired look then, too. 
    Peter's pointing out that you could inadvertently move just one of the corners with the direct selection tool and have a frame that isn't a rectangle and then you loose the text box vertical justification option. If you are on OSX you can use this script to square up a selected skewed box:
    tell application "Adobe InDesign CS3"
    set {a, b, c, d} to geometric bounds of selection
    set entire path of path 1 of selection to {{b, a}, {d, a}, {d, c}, {b, c}}
    end tell

  • Add Text Justification Options

    For text fields added to slides, the ability to control justification (e.g., Left, Center, Right), would be very helpful.

    If I understand the use-case correctly, you want the options selected from the addRemove component on page 1 to form the basis of the available options in the addRemove list on page 2.
    The recommended method of transfering values from one page to another is via the RequestBean. In your case, I suggest adding two properties to the request bean. The first we'll call "pageOneAddedValues", and it will be of type java.lang.Object[]. The second we'll call "pageTwoOptions", and it will be of type com.sun.rave.web.ui.model.Option[], and it should probably also be read-only. You bind the Selected property of the page 1 addRemove to the pageOneAddedValues property, and you bind the Items property of the page 2 addRemove to the pageTwoOptions property.
    The trick is to use the values set the pageOneAddedValues property as the seed for the options returned by the pageTwoOptions property. Assuming the simplest case where the option labels are the same as the values, this can be simply:
        public Option[] getPageTwoOptions() {
            Object[] selectedValues = this.getPageOneAddedValues();
            if (selectedValues == null)
                return new Option[0];
            Option[] options = new Option[selectedValues.length];
            for (int i = 0; i < options.length; i++) {
                options&#x5b;i] = new Option(selectedValues&#x5b;i]);
            return options;
        }Good luck!
    // Gregory
    Message was edited by:
    gjmurphy
    Message was edited by:
    gjmurphy

  • Text Wrap disables vertical justification

    Hi,
    I am using InDesign CS3 5.0.4 on Windows XP Pro SP3.
    I have the following problem: I have a text frame with vertical centrered text in it. Now when I put some object with text wrap near it, the vertical justification is just ignored (also blanked out in text frame options) and the text justifies at the top of the text frame. I think this is very annoying and I don't understand why this works the way it does. I remember this problem also ocurred in QuarkXPress but I hoped Adobe would do it better :)
    I hope someone can explain this to me. Thanks.
    Frank

    How near is near? If the object is too close to the text for comfort it's going to need text wrap or there'll be a
    collision. And vertical justification will be lost.
    Does the object span the full depth of the text frame? If so, just ignore text wrap, narrow the text frame and take its
    edge away from the object. If the object cuts into the text frame so some lines are wrapped and others are not, then the
    vertical justification will be lost.
    You could fiddle it by eye by breaking the text into three frames, with the text in the top frame aligned to the bottom,
    the text in the middle and bottom frame aligned to the top. Then align the text in all the frames to the same baseline
    grid (you can set a grid for each frame), and jiggle the depths appropriately.
    k

  • JMenuItem.

    Dear all,
    I downloaded the following program from Sun to create JMenuBar and JManuItem but there is no function. I need to display say 'Hello World' when I click one of the JMenuItem. May I know how to write the function in the following context ?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JCheckBoxMenuItem;
    import javax.swing.JRadioButtonMenuItem;
    import javax.swing.ButtonGroup;
    import javax.swing.JMenuBar;
    import javax.swing.KeyStroke;
    import javax.swing.ImageIcon;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JFrame;
    * This class exists solely to show you what menus look like.
    * It has no menu-related event handling.
    public class MenuLookDemo extends JFrame {
        JTextArea output;
        JScrollPane scrollPane;
        public MenuLookDemo() {
            JMenuBar menuBar;
            JMenu menu, submenu;
            JMenuItem menuItem;
            JCheckBoxMenuItem cbMenuItem;
            JRadioButtonMenuItem rbMenuItem;
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
            //Add regular components to the window, using the default BorderLayout.
            Container contentPane = getContentPane();
            output = new JTextArea(5, 30);
            output.setEditable(false);
            scrollPane = new JScrollPane(output);
            contentPane.add(scrollPane, BorderLayout.CENTER);
            //Create the menu bar.
            menuBar = new JMenuBar();
            setJMenuBar(menuBar);
            //Build the first menu.
            menu = new JMenu("A Menu");
            menu.setMnemonic(KeyEvent.VK_A);
            menu.getAccessibleContext().setAccessibleDescription(
                    "The only menu in this program that has menu items");
            menuBar.add(menu);
            //a group of JMenuItems
            menuItem = new JMenuItem("A text-only menu item",
                                     KeyEvent.VK_T);
            //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
            menuItem.setAccelerator(KeyStroke.getKeyStroke(
                    KeyEvent.VK_1, ActionEvent.ALT_MASK));
            menuItem.getAccessibleContext().setAccessibleDescription(
                    "This doesn't really do anything");
            menu.add(menuItem);
            menuItem = new JMenuItem("Both text and icon",
                                     new ImageIcon("images/middle.gif"));
            menuItem.setMnemonic(KeyEvent.VK_B);
            menu.add(menuItem);
            menuItem = new JMenuItem(new ImageIcon("images/middle.gif"));
            menuItem.setMnemonic(KeyEvent.VK_D);
            menu.add(menuItem);
            //a group of radio button menu items
            menu.addSeparator();
            ButtonGroup group = new ButtonGroup();
            rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
            rbMenuItem.setSelected(true);
            rbMenuItem.setMnemonic(KeyEvent.VK_R);
            group.add(rbMenuItem);
            menu.add(rbMenuItem);
            rbMenuItem = new JRadioButtonMenuItem("Another one");
            rbMenuItem.setMnemonic(KeyEvent.VK_O);
            group.add(rbMenuItem);
            menu.add(rbMenuItem);
            //a group of check box menu items
            menu.addSeparator();
            cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
            cbMenuItem.setMnemonic(KeyEvent.VK_C);
            menu.add(cbMenuItem);
            cbMenuItem = new JCheckBoxMenuItem("Another one");
            cbMenuItem.setMnemonic(KeyEvent.VK_H);
            menu.add(cbMenuItem);
            //a submenu
            menu.addSeparator();
            submenu = new JMenu("A submenu");
            submenu.setMnemonic(KeyEvent.VK_S);
            menuItem = new JMenuItem("An item in the submenu");
            menuItem.setAccelerator(KeyStroke.getKeyStroke(
                    KeyEvent.VK_2, ActionEvent.ALT_MASK));
            submenu.add(menuItem);
            menuItem = new JMenuItem("Another item");
            submenu.add(menuItem);
            menu.add(submenu);
            //Build second menu in the menu bar.
            menu = new JMenu("Another Menu");
            menu.setMnemonic(KeyEvent.VK_N);
            menu.getAccessibleContext().setAccessibleDescription(
                    "This menu does nothing");
            menuBar.add(menu);
        public static void main(String[] args) {
            MenuLookDemo window = new MenuLookDemo();
            window.setTitle("MenuLookDemo");
            window.setSize(450, 260);
            window.setVisible(true);
    }

    In the same tutorial there is a section titled "Handling Events From Menu Items" which includes sample code:
    http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#event

  • Justification of field in ALV

    Hi Gurus,
    I developed an ALV Report . but I want display the Total Amount field header as left and the value in the column is right justification.
    Please any body know give me the answer.
    Regards,
    Shashikumar.G
    Message was edited by:
            Shashikumar Guntuka
    Message was edited by:
            Shashikumar Guntuka

    Hi Kaushik,
    Your answer is wa_fildcat-just = 'C'.
    but I want Header for field (field name ) is Left justifcation and the values in the column is Right justification.
    Thanks and Regards
    Shashikumar.G
    Message was edited by:
            Shashikumar Guntuka

  • Add Listener to Unknown Number of JMenuItems

    How can I add an ActionListener to each JMenuItem by cycling through an unknown number of menu items?
    I have a program that prompts the user for a database, then creates a JMenu of table names based on whatever database the user selects.
    This means that I don't know the table names or number of tables that will be added to the JMenu.
    I need to add an ActionListener to EACH JMenuItem. The problem is that I am only able to select one table from the menu. Subsequent menu clicks (on different table names) have no affect on the output.
    Here is an excerpt of my code:
    ResultSet rs = md.getTables(null, null, null, types);
    while (rs.next()) {
    tables.add(rs.getString("table_name"));
    for (Iterator i = tables.iterator(); i.hasNext(); )
    String table = (String) i.next();
    JMenuItem mi = new JMenuItem(table);
    j1.add(mi);
    mi.addActionListener(this);
    [END CODE]
    Thanks for any help you can give!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    I got it. It turns out that I WAS setting the listeners correctly. My additonal output was "hidden" in the window. I found it by pure luck when I expanded the window size.
    I added a line to remove all components from the JPanel before adding a new one and this "refresh" worked.
    Thanks fot the help anyway! It is greatly appreciated.

  • How can I distinguish a JMenuItem , JPopupMenu and TopLevelMenu?

    I used the following methods to get the component who (a menu)gains the focus:
    JComponent com = JFrmame.getFocusOwner();
    or
    MenuSelectionManager menuMgr = MenuSelectionManager.defaultManager();
    MenuElement[] menuPath = menuMgr.getSelectedPath();
    if(menuPath != 0) {
    JComponent comp = Array.get(menuPath, menuPath.length-1); // this is the item with the focus
    then I need to use getAction() to get the menuItem's action. But how can I filter JMenuItem and JPopUpMenu from TopLevelMenu (JMenuBar item) ?
    Thanks!

    The instanceof may provide the simplest solution, since JPopupMenu, JMenuBar and JMenuItem don't have any kind of ancestor relationship with each other.if (comp instanceof JPopupMenu) {
        // Popup
    } else if (comp instanceof JMenuItem) {
        // Item
    } else if (comp instanceof JMenuBar) {
        // Bar
    } else ...?Hope this helps,
    -Troy

  • How do I find the parent JFrame of a JMenuItem?

    When an ActionEvent occurs from a JMenuItem selection, how can
    I get a reference to the JFrame the JMenuItem is on?
    Thanks

    Good afternoon...
    it's a pretty good / standard idea to make your event-thread a subclass of the JFrame. i.e.:
    public class MySwingApp extends JFrame implements ActionListener {
        public MySwingApp() [
            super("My App Title");
            // ...build your GUI...
            // ...register this as your action listener for the menu items...
        /* this is in the class that is the JFrame of the application */
        public void actionPerformed(ActionEvent ae) {
            System.out.println(ae.getCommand());
    }hope that helps
    Schultz

  • List View Justification incorrect after sorting

    I am using a list view to display some data in Xcelsius SP3.  I have set the justification to 'Left' for the List View object and when the object is first display all numbers are correctly aligned.  However, if a sort is done by one of the column headings some numbers appear to shift further left than others.  This causes the data to look misaligned.  Anyone else experiencing this or have an idea of what may correct it?
    Thanks

    I downloaded and installed FixPack 3.4 for Xcelsius 2008 SP3 and re-created the SWF file but still had no luck.  The labels of the List View still do not align correctly when sorting or even scrolling in the table.  I have not yet opened a Support note in marketplace but plan on doing so soon.  I will update this message with the note # and any responses that I receive. 
    I have to believe with as much as the list view component is used that someone else has had this happen to them.  Any input would be greatly appreciated.
    Thanks,
    Scott

  • How can I have a shortcut key that is not a JMenuItem

    Hi,
    I'm trying to make "ctrl-f" a shortcut key in my program.
    I know I can do this as a JMenuItem by:
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK));
    However, I would rather not have it in the menu.
    How would I do this without having it as a JMenuItem?
    Thanks,
    Daniel Lorimer

    As a user I hate designs like this. How am I supposed to know what all the shortcut keys are? Using a menu item is a form of self documentation
    Anyway, check out the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to Use Key Bindings.

  • Dynamic addition of  JMenuItem in JMenu

    I am trying to create a menu for my project. For that i have added the main menus and for each menu there will be menu item. But the problem is i will get the list of menu items for each menu , only at the runtime of my project. i.e. i wabt to add progrramatically add the menu items. Iam really confused with this. I will appriciate if any one help me on this.
    And also i want to know ..is that possible to get the mouse listener for menu.
    Thank in advance
    Regards,
    SAthish

    You can add and remove menu items from the jmenu dynamically, the only thing you will have to take care of is invoking validate() after each insertion/deletion (it's a bit buggy there). All you have to do is create the items on demand and add (remove) them via the add(JMenuItem) (remove(JMenuItem)) method.
    As for your second question, a JMenu is nothing but a JComponent, so you should be able to add a mouse listener like you would with any other component...

  • Column justification for spanning paragraphs

    I'm brand new to InDesign. I have a lot of experience with Framemaker and need to accomplish something that was routine with that product.
    First off, due to constant changes and updates, book length, and accidental movement of frames (even by the ID house we work with), individually adjusting frames is disabled (text frame layers are locked, but selection of locked objects is enabled, so text editing will work).
    We're producing long technical manuals and need to leave the outside edge of the page (opposite the binding) mostly clear. This will be used for user and author notes, as well as sidebars. Those I know I can do those with anchored frames.
    Frequently, we also need to have paragraphs span into into that reserved space in order to preserve required line breaks without making text unreadably small. We'll need to do the same thing with tables. How does one accomplish this in InDesign? On obvious way to do this would be to use three columns and set most paragraph styles to span across two of them. How does one specify that if all of the columns cannot be used for text flow (due to spanning), only the innermost columns are to be used (text justification in the columns needs to remain as-is).
    Can I force text to run outside of a frame?
    If these can't be done, can anchored frames be used inline? How do you assure accurate spacing between paragraphs in and out of the frame and how do you make these frames break correctly across pages?
    Is there a different workaround? A vendor plug-in?
    Thanks,
    Jeremy

    jcs-7689 wrote:
    I'm brand new to InDesign. I have a lot of experience with Framemaker and need to accomplish something that was routine with that product.
    First off, due to constant changes and updates, book length, and accidental movement of frames (even by the ID house we work with), individually adjusting frames is disabled (text frame layers are locked, but selection of locked objects is enabled, so text editing will work).
    We're producing long technical manuals and need to leave the outside edge of the page (opposite the binding) mostly clear. This will be used for user and author notes, as well as sidebars. Those I know I can do those with anchored frames.
    Frequently, we also need to have paragraphs span into into that reserved space in order to preserve required line breaks without making text unreadably small. We'll need to do the same thing with tables. How does one accomplish this in InDesign? On obvious way to do this would be to use three columns and set most paragraph styles to span across two of them. How does one specify that if all of the columns cannot be used for text flow (due to spanning), only the innermost columns are to be used (text justification in the columns needs to remain as-is).
    Can I force text to run outside of a frame?
    If these can't be done, can anchored frames be used inline? How do you assure accurate spacing between paragraphs in and out of the frame and how do you make these frames break correctly across pages?
    Is there a different workaround? A vendor plug-in?
    Thanks,
    Jeremy
    I know FrameMaker well, but I'm having difficulty understanding how your FrameMaker pages look, and how you achieved that result. It would be helpful to see some example pages/spreads, and some explanatory text.
    Was your FrameMaker workflow fully-automated? If not, what manual operations were needed?
    This info would be helpful in finding InDesign solutions to achieve the same, or similar, results.
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices

  • Right Justification in File Content Conversion

    I have a requirement where the data should be right justified in File content conversion of a Receiver Adapter .
    For example  it should be coming as   "      5864"  instead of "5864     ". Please help in completing this requirement.

    Hi Srinath
    AFAIK, there is no setting in FCC to achieve this. You can do this instead in the Message Mapping step by doing a right justify on that target fields.
    You can search for plenty of solutions on the internet to perform a right justify and include it in a UDF.
    Below is an example of a UDF of execution type single values with single input. It right justifies the String based on a total length of 15. You can change the field length according to your requirement.
    return String.format("%15s", input);
    Rgds
    Eng Swee

Maybe you are looking for