Customizing JPopupMenu's L&F

Hi all,
When removing all borders and overriding 'paintComponent(Graphics g)' methods there is still space at the bottom and top of a 'JPopupMenu' drop down menu. This space shrinks and grows as the menu size varies as well. How can I get at the space and remove it. I take it can't have anything to do with 'Insets' since it shrinks and grows so it must be a component.
//|----------------------------------------|
//|            (Extra space)               |
//|----------------------------------------|
//|                                        |
//|  FILE                                  |
//|                                        |
//|                                        |
//|----------------------------------------|
//|  SAVE                                  |
//|                                        |
//|                                        |
//|                                        |
//|----------------------------------------|
//|                                        |
//|                                        |
//                  |
//                  |
//                  |
//                  |
//                 \/Devyn

Hi bbritta,
Thnx for looking into this. Tried, I have this for myPopupMenu. I have this for JMenu and JMenuItem as well as 'setBorder(null)' for either and all components associated I use for my menu. Still no change.
Devyn

Similar Messages

  • Custom JButton for JPopupMenu

    I need to make a custom PopupMenu Button . This button needs to be added to the custom JPopupmenu . This custom button must have the look and feel of a typical menu item. Basically it should have a typical features of a checkboxmenuitem where I have an check.jpg for check and uncheck of the button. How do I reproduce the look and feel of a menuitem. What changes do i make in the below code. Basically no border, button press should not be there. It should not look like we are adding JButtons to the user
    import javax.swing.Action;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.border.EmptyBorder;
    public class XCheckedButton
            extends JButton {
        private boolean flag;
        private ImageIcon checkedIcon;
        public XCheckedButton() {
            super();
        public XCheckedButton(Action a) {
            this();
            setAction(a);
        public XCheckedButton(Icon icon) {
            super(icon);
        public XCheckedButton(String text, Icon icon) {
            super(text, icon);
        public XCheckedButton(String text) {
            super(text);
         public ImageIcon getCheckedIcon() {
              return checkedIcon;
         public void setCheckedIcon(boolean state) {
              this.checkedIcon = checkedIcon;
    }

    Thanks a lot. Here are my 2 java files and right below is the probelm I am facing when USing JMenuItems. Thats the reason why i switched over to JButtons.
    JframePopupMenu.java
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JCheckBoxMenuItem;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class JFramePopupMenu extends JFrame  {
         private static final long serialVersionUID = 1;
         private JPanel jContentPane = null;
         private JButton jbnPopup = null;
         private JTextField jtfNumOfMenus = null;
         private JLabel lblNumElem = null;
         JTextArea output;
        JScrollPane scrollPane;
        String newline = "\n";
        ScrollablePopupMenu scrollablePopupMenu = new ScrollablePopupMenu(JFramePopupMenu.this.getGraphicsConfiguration());
         private JButton getBtnPopup() {
              if (jbnPopup == null) {
                   jbnPopup = new JButton();
                   jbnPopup.setText("View Popup");
                   jbnPopup.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             int n = Integer.parseInt(getTxtNumElem().getText());
                             JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
                             cbMenuItem.addActionListener(new ActionListener(){
                                  public void actionPerformed(ActionEvent e) {
                                       System.out.println( e );
                                       scrollablePopupMenu.hidemenu();
                           cbMenuItem.setMnemonic(KeyEvent.VK_C);
                           scrollablePopupMenu.add(cbMenuItem);
                             for (int i=0;i<n;i++){
                                  JMenuItem xx = new JMenuItem(" JMenuItem  " + (i+1));
                                       xx.addActionListener(new ActionListener(){
                                       public void actionPerformed(ActionEvent e) {
                                            System.out.println( e );
                                            scrollablePopupMenu.hidemenu();
                             //     scrollablePopupMenu.add(new JButton(" JMenuItem  " + (i+1)));
                                  scrollablePopupMenu.add(xx);
                             scrollablePopupMenu.show(jbnPopup, jbnPopup.getWidth()*3, 0);
              return jbnPopup;
         private JTextField getTxtNumElem() {
              if (jtfNumOfMenus == null) {
                   jtfNumOfMenus = new JTextField();
                   jtfNumOfMenus.setColumns(3);
                   jtfNumOfMenus.setText("60");
              return jtfNumOfMenus;
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        JFramePopupMenu thisClass = new JFramePopupMenu();
                        thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        thisClass.setVisible(true);
         public JFramePopupMenu() {
              super();
              initialize();
         private void initialize() {
              this.setSize(274, 109);
              this.setContentPane(getJContentPane());
              this.setTitle("Scrollable JPopupMenu");
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   lblNumElem = new JLabel();
    //               lblNumElem.setText("N�mero de elementos del Men�");
                   FlowLayout flowLayout = new FlowLayout();
                   flowLayout.setHgap(8);
                   flowLayout.setVgap(8);
                   jContentPane = new JPanel();
                   jContentPane.setLayout(flowLayout);
                   jContentPane.add(getBtnPopup(), null);
                   jContentPane.add(lblNumElem, null);
                   jContentPane.add(getTxtNumElem(), null);
              return jContentPane;
    ScrollablePopupMenu.java
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GraphicsConfiguration;
    import java.awt.GridLayout;
    import javax.swing.JFrame;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JPopupMenu;
    import javax.swing.JScrollPane;
    import javax.swing.JSeparator;
    public class ScrollablePopupMenu extends JPopupMenu {
         private static final long serialVersionUID = 1;
         private JPanel panelMenus = null;
         private JScrollPane scroll = null;
         public ScrollablePopupMenu(GraphicsConfiguration gc) {
              super();
              scroll = new JScrollPane();
              panelMenus = new JPanel();
              panelMenus.setLayout(new GridLayout(0,1));
              scroll.setViewportView(panelMenus);
              scroll.setBorder(null);
              scroll.setMaximumSize(new Dimension(scroll.getMaximumSize().width,
                        this.getToolkit().getScreenSize().height -
                        this.getToolkit().getScreenInsets(gc).top -
                        this.getToolkit().getScreenInsets(gc).bottom - 4));
              super.add(scroll);
         public void show(Component invoker, int x, int y) {
              this.pack();
              panelMenus.validate();
              int maxsize = scroll.getMaximumSize().height;
              int realsize = panelMenus.getPreferredSize().height;
              int sizescroll = 0;
              if (maxsize < realsize) {
                   sizescroll = scroll.getVerticalScrollBar().getPreferredSize().width;
              scroll.setPreferredSize(new Dimension(
                        scroll.getPreferredSize().width + sizescroll,
                        scroll.getPreferredSize().height));
              this.setLocation( x, y);
              this.setVisible(true);
         public void hidemenu(){
              if(this.isVisible()){
                   this.setVisible(false);
         public JMenuItem add(JMenuItem menuItem) {
              panelMenus.add(menuItem);
              return menuItem;
         public void addSeparator() {
              panelMenus.add(new JSeparator());
    Problem 1: Not able to Scroll down when frame is Large
    My application is a large frame and when I invoke the JPopupMenu on it I am not able to scroll.
    In the example application also I found the same problem when I maximize the frame. I am able to see the JPopupMenu but not able to scroll on it.

  • Focus problem when JPopupMenu is shown

    I have compiled and ran the following 'JPopupTest.java' in JDK 1.4.1 on Windows. Kindly conduct the two tests as given below
    First Test :
    ============
    The class shows an editable JComboBox and a JButton when visible. Now click the down-arrow button of the JComboBox and make the drop-down popup visible. Then click on the "OK" button while the popup is visible. The popup gets hidden and a dialog is displayed as it should be.
    Second Test :
    =============
    Run the appilcation again. This time type something in the editable textfield of the JComboBox. A custom JPopupMenu with the text "Hello World" would be visible. Then click on the "OK" button while the popup is visible. The expected dialog is not shown. The custom JPopupMenu gets hidden. Now click on "OK" button again. The dialog is visible now.
    My Desire :
    ===========
    When I click on the "OK" button in the "Second Test" the JPopupMenu should get hidden and the dialog gets displayed (as it happens for the "First Test") in one click.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import javax.swing.plaf.basic.*;
    import java.util.*;
    public class JPopupTest extends JPanel implements DocumentListener, ActionListener
         JButton button;
         Vector vec;
         JComboBox jcombobox;
         JPopupMenu jpopupmenu;
         BasicComboBoxEditor _bcbe;
         JTextField jtextfield;
         public JPopupTest()
            vec = new Vector();
               vec.addElement("One");
            vec.addElement("Two");
            vec.addElement("Three");
            vec.addElement("Four");
            vec.addElement("Five");
            vec.addElement("Six");
            vec.addElement("Seven");
            vec.addElement("Eight");
            vec.addElement("Nine");
            vec.addElement("Ten");
            jcombobox = new JComboBox(vec);
            jcombobox.setEditable(true);
            _bcbe = ((BasicComboBoxEditor) jcombobox.getEditor());
            jtextfield = ((JTextField) _bcbe.getEditorComponent());
            jtextfield.getDocument().addDocumentListener(this);
            add(jcombobox);
            button = new JButton("OK");
            button.addActionListener(this);
            add(button);
            jpopupmenu = new JPopupMenu();
            jpopupmenu.add("Hello World");
         public void insertUpdate(DocumentEvent e)  {changedUpdate(e);}
         public void removeUpdate(DocumentEvent e)  {changedUpdate(e);}
            public void changedUpdate(DocumentEvent e)
            if(!jpopupmenu.isVisible())
            jpopupmenu.show(jcombobox, 0, jcombobox.getHeight());
            jtextfield.requestFocus();
         public void actionPerformed(ActionEvent e)
            JOptionPane.showMessageDialog(this, "OK button was pressed");
         public static void main(String[] args)
            JPopupTest test = new JPopupTest();
            JFrame jframe = new JFrame();
            jframe.getContentPane().add(test);
            jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            jframe.setSize(200,100);
            jframe.setVisible(true);

    See the code below with auto complete of text. When button is pressed, still TF gets focus after JOptionPane dialog is closed.
    -Pratap
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.plaf.basic.*;
    public class JPopupTest extends JPanel implements ActionListener {
         JButton button;
         Vector vec;
         JComboBox jcombobox;
         BasicComboBoxEditor _bcbe;
         JTextField jtextfield;
         MyComboUI comboUi = new MyComboUI();
         public JPopupTest() {
              vec = new Vector();
              vec.addElement("One");
              vec.addElement("Two");
              vec.addElement("Three");
              vec.addElement("Four");
              vec.addElement("Five");
              vec.addElement("Six");
              vec.addElement("Seven");
              vec.addElement("Eight");
              vec.addElement("Nine");
              vec.addElement("Ten");
              jcombobox = new JComboBox(vec);
              jcombobox.setEditable(true);
              jcombobox.setUI(comboUi);
              add(jcombobox);
              button = new JButton("OK");
              button.addActionListener(this);
              add(button);
              _bcbe = ((BasicComboBoxEditor) jcombobox.getEditor());
              jtextfield = ((JTextField) _bcbe.getEditorComponent());
              jtextfield.addCaretListener(new CaretListener() {
                        public void caretUpdate(CaretEvent e) {
                             if (!jcombobox.isPopupVisible() && jtextfield.isShowing() &&
                                       jtextfield.hasFocus()) {
                                  jcombobox.showPopup();
                             String text = jtextfield.getText().toLowerCase();
                             int index = -1;
                             for (int i = 0; i < jcombobox.getItemCount(); i++) {
                                  String item = ((String) jcombobox.getItemAt(i)).toLowerCase();
                                  if (item.startsWith(text)) {
                                       index = i;
                                       break;
                             if (index != -1) {
                                  comboUi.getList().setSelectedIndex(index);
                             } else {
                                  comboUi.getList().clearSelection();
                   jtextfield.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent e) {
                             if (e.getKeyCode() == e.VK_ENTER) {
                                  Object value = comboUi.getList().getSelectedValue();
                                  jcombobox.setSelectedItem(value);
                                  jcombobox.hidePopup();
         public void actionPerformed(ActionEvent e) {
              JOptionPane.showMessageDialog(this,"OK button was pressed");
              jtextfield.requestFocus();
         public static void main(String[] args) {
              JPopupTest test = new JPopupTest();
              JFrame jframe = new JFrame();
              jframe.getContentPane().add(test);
              jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              jframe.setSize(200,100);
              jframe.setVisible(true);
         public class MyComboUI extends BasicComboBoxUI {
              public JList getList() {
                   return listBox;

  • JPopupMenu ignores setOpaque(false) near screen edges

    Dear group
    I try to paint a custom JPopupMenu with transparency, but this is ignored when the popup is opened so it overlaps near screen edges (bottom and right side). This is also the case if the popup overlaps the Microsoft Windows toolbar at the bottom.
    I may be able to emulate JPopupMenus using custom components in a JLayeredPane, but can anyone explain the above behaviour?
    Thanks and Best Regards,
    Aksel, Denmark
    Environment: j2sdk-se 1.6.0_10 and windows xp
    Example:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Rectangle;
    import java.awt.Toolkit;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPopupMenu;
    public class TransparencyPopupNearBorderTest {
    public static void main(String[] args) {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setBounds(new Rectangle(screenSize));
    frame.setUndecorated(true);
    frame.setPreferredSize(screenSize);
    frame.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseReleased(MouseEvent e) {
    JPopupMenu popup = new JPopupMenu();
    popup.setOpaque(false);
    JLabel label = new JLabel("TRANSPARENT");
    label.setFont(new Font("Helvetica", Font.PLAIN, 42));
    popup.add(label);
    popup.setLightWeightPopupEnabled(false);
    popup.show(frame, e.getX(), e.getY());
    frame.getContentPane().setBackground(Color.BLUE);
    frame.pack();
    frame.setVisible(true);
    }

    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
    I don't know if transparency painting has changed in 1.6.0_10. Prior to that I believe transparency can only be achieved in lightweight components (ie. Swing does all the painting). JFrame, JWindow and JDialog are not lightweight because they use OS components.
    In the case of a popup, it is lightweight when entirely contained within its parent frame. But a lightweight popup can not be painted outside the bounds of the frame so a JWindow (I believe) is used as the popup, which can't be transparent.

  • Disabled components: to popup or not to popup context menu?

    Hi experts,
    just noticed that Swing pops up a component menu on mouse click even if the component isn't enabled. Seems to contradict the general rule to not allow "active" interaction (vs. "passive" as f.i. still showing the tooltip, the distinction is probably freely invented but serves me well enough ;) with a disabled component.
    Could half-way live with that - except that then all menu items need to be disabled individually. Another option would be to return a null componentPopup if disabled. Not generally applicable because requires subclassing. Yet another might be to force-inject a MouseListener into the rootPane: it would intercept and swallow the popup triggers if the target is disabled, otherwise delegate to the ui-installed listener.
    Comments please?
    Thanks
    Jeanette

    >
    release is out (here's a screenshot: http://www.jyloo.com/news/?pubId=1297423104000 - commercial, though) - so have a bit more time right now to tackle this
    What puzzled me most in your comments was:
    >
    (and set the show popup action enabled/disabled as well). because I expected that to be not a problem at all: RootPane's action in isEnabled(sender) first checks if the sender is the focusOwner and returns false if not. Disabled components cannot be focusOwner, so safe territory. Except ... they can, even if there are enabled focusable components around. Turns out that the KeyboardFocusManager isn't clever enough to keep transfering the focus when a whole bunch of components is disabled. Or maybe it's a timing issue, as focus transfers can be asynchronous, and/or are tricky anyway, don't know. Whatever, when disabling a bunch of components, it must be done in the inverse order of the focusTransferCycle ... and that's completely unmanageable except for most simple contexts, like focus cycle is the same as insertion order, than reversing disable loop is a brittle option
    // before calling this, focus on parent.getComponent(0)
    // the natural way of disabling the children
    for (Component child: parent.getComponents()) {
         child.setEnabled(false);
    // after the call, focus on parent.getComponent(1)
    // inversing
    for (int i = parent.getComponentCount() - 1; i >= 0; i--) {
       parent.getComponent(i).setEnabled(false);
    // focus somewhere elseINCREDIBLE ...
    overriding getComponentPopup to return null if disabled (as I did as a quick measure) is not really an option - don't want to override each and every component ;-) Another hook - not clean either, but at least manageable, might be a custom JPopupMenu: subclass and show only if enabled.
    @override
    public void show(Component invoker, int x, int y) {
        if (!invoker.isEnabled()) return;
        super.show(..)
    }This still leaves the action enabled fooled - reports true because the invoker has a componentPopup - but then, a disable comp should be focusOwner anyway.
    Cheers
    Jeanette

  • Small issue with custom table cell editor and unwanted table row selection

    I'm using a custom table cell editor to display a JTree. Thing i notice is that when i select a value in the tree pop-up, the pop-up closes (as it should) but then every table row, from the editing row to the row behind the pop-up when i selected the value becomes highlighted. I'm thinking this is a focus issue, but it thought i took care of that. To clairfy, look at this: Before . Notice how the "Straightening" tree item is roughly above the "Stock Thickness" table row? When i select Straightening, this is what happens to my table: After .
    My TreeComboBox component:
    public class TreeComboBox extends JPanel implements MouseListener {
        private JTextField itemField;
        private TreeModel treeModel;
        private ArrayList<ActionListener> actionListeners = new ArrayList<ActionListener>();
        private Object selectedItem;
         * Creates a new <code>TreeComboBox</code> instance.
         * @param treeModel the tree model to be used in the drop-down selector.
        public TreeComboBox(TreeModel treeModel) {
            this(treeModel, null);
         * Creates a new <code>TreeComboBox</code> instance.
         * @param treeModel the tree model to be used in the drop-down selector.
         * @param selectedItem tree will expand and highlight this item.
        public TreeComboBox(TreeModel treeModel, Object selectedItem) {
            this.treeModel = treeModel;
            this.selectedItem = selectedItem;
            initComponents();
         * Returns the current drop-down tree model.
         * @return the current <code>TreeModel</code> instance.
        public TreeModel getTreeModel() {
            return treeModel;
         * Sets the tree model.
         * @param treeModel a <code>TreeModel</code> instance.
        public void setTreeModel(TreeModel treeModel) {
            this.treeModel = treeModel;
         * Returns the selected item from the drop-down selector.
         * @return the selected tree object.
        public Object getSelectedItem() {
            return selectedItem;
         * Sets the selected item in the drop-down selector.
         * @param selectedItem tree will expand and highlight this item.
        public void setSelectedItem(Object selectedItem) {
            this.selectedItem = selectedItem;
            String text = selectedItem != null ? selectedItem.toString() : "";
            itemField.setText(text);
            setToolTipText(text);
         * Overridden to enable/disable all child components.
         * @param enabled flat to enable or disable this component.
        public void setEnabled(boolean enabled) {
            itemField.setEnabled(enabled);
            super.setEnabled(enabled);
        public void addActionListener(ActionListener listener) {
            actionListeners.add(listener);
        public void removeActionListener(ActionListener listener) {
            actionListeners.remove(listener);
        // MouseListener implementation
        public void mouseClicked(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
        public void mousePressed(MouseEvent e) {
        public void mouseReleased(MouseEvent e) {
            showPopup();
        private void initComponents() {
            setLayout(new GridBagLayout());
            itemField = new JTextField();
            itemField.setEditable(false);
            itemField.setText(selectedItem != null ? selectedItem.toString() : "");
            itemField.addMouseListener(this);
            add(itemField, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,
                    GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
        private void showPopup() {
            final TreePopup popup = new TreePopup();
            final TreeComboBox tcb = this;
            final int x = itemField.getX();
            final int y = itemField.getY() + itemField.getHeight();
            int width = itemField.getWidth() + popupButton.getWidth();
            Dimension prefSize = popup.getPreferredSize();
            prefSize.width = width;
            popup.setPreferredSize(prefSize);
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    popup.show(tcb, x, y);
                    popup.requestFocusInWindow();
        private void fireActionPerformed() {
            ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "TreeComboBoxSelection");
            for (ActionListener listener : actionListeners) {
                listener.actionPerformed(e);
        private class TreePopup extends JPopupMenu {
            private JTree tree;
            private JScrollPane scrollPane;
            public TreePopup() {
                initComponents();
                initData();
            private void initData() {
                if (treeModel != null) {
                    tree.setModel(treeModel);
            private void initComponents() {
                setFocusable(true);
                setFocusCycleRoot(true);
                tree = new JTree();
                tree.setRootVisible(false);
                tree.setShowsRootHandles(true);
                tree.setFocusable(true);
                tree.setFocusCycleRoot(true);
                tree.addTreeSelectionListener(new TreeSelectionListener() {
                    public void valueChanged(TreeSelectionEvent e) {
                        tree_valueChanged(e);
                scrollPane = new JScrollPane(tree);
                add(scrollPane);
            private void tree_valueChanged(TreeSelectionEvent e) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
                setSelectedItem(node.getUserObject());
                fireActionPerformed();
                this.setVisible(false);
    }My TreeComboBoxTableCellEditor:
    public class TreeComboBoxTableCellEditor extends AbstractCellEditor implements TableCellEditor, ActionListener {
        protected TreeComboBox treeComboBox;
        protected ArrayList<CellEditorListener> cellEditorListeners = new ArrayList<CellEditorListener>();
        public TreeComboBoxTableCellEditor(TreeComboBox treeComboBox) {
            this.treeComboBox = treeComboBox;
            treeComboBox.addActionListener(this);
        public Object getCellEditorValue() {
            return treeComboBox.getSelectedItem();
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
            treeComboBox.setSelectedItem(value);
            return treeComboBox;
        public void actionPerformed(ActionEvent e) {
            stopCellEditing();
    }Any thoughts?
    Edited by: MiseryMachine on Apr 3, 2008 1:21 PM
    Edited by: MiseryMachine on Apr 3, 2008 1:27 PM

    As I said, you have to have empty context elements before additional rows will be open for input.
    For instance if you want to start with 5 rows available for input do the following to your internal table that you will bind:
    data itab type standard table of sflight.
    do 5 times.
      append initial line to itab.
    enddo.
    context_node->bind_table( itab ).
    The other option if you need n number of rows is to add a button to the table toolbar for adding more rows. When this button is pressed, you add a new context element to the node - thereby creating a new empty row in the table.

  • Overriding double click in JTable custom cell

    I have a JTable where I reset the custom cells to become editable on a single click instead if a double using:
    ((DefaultCellEditor)table.getDefaultEditor(String.class)).setClickCountToStart(1);
    Now what I need to do is display a JPopupMenu click a cell is double clicked. This works on cells that are not editable but the problem is that the user needs the popup dialog to display info for the cells that are editable.
    I have used the basic way to implement a double click on a certain column (in this case my third column):
    public void mouseClicked(MouseEvent e){
                   if (e.getClickCount() == 2 && table.getSelectedColumn() == 2 ){
                        popupMenu.show( e.getComponent(),
    e.getX(), e.getY() );
    But when double clicking, nothing happens.
    Anyone have any idea to implement this or over-ride an editable cell?
    Thanks,
    Chris

    This still says <identifier> expect, how can I resove this please? Then you still have something wrong with your code. Since you didn't post your code how are we supposed to help?
    The proper way to ask a question is to include your demo code that trys to illustrate the problem. Something like the following:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TableRightClick extends JFrame
         public TableRightClick()
              JTable table = new JTable(10, 5);
              table.addMouseListener( new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        if ( SwingUtilities.isRightMouseButton(e) )
    //                    if (e.isPopupTrigger())
                             JTable source = (JTable)e.getSource();
                             int row = source.rowAtPoint( e.getPoint() );
                             int column = source.columnAtPoint( e.getPoint() );
                             System.out.println(column);
                             source.changeSelection(row, column, false, false);
              table.setPreferredScrollableViewportSize(table.getPreferredSize());
              getContentPane().add( new JScrollPane(table) );
         public static void main(String[] args)
              TableRightClick frame = new TableRightClick();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible( true );
    }

  • A custom version of JOptionPane.showInputDialog();

    I am trying to create a custom input dialog window so that I can have a right click event handler which lets me copy/cut/paste text using the mouse. However, after constructing the following code [as a standalone class, how I plan on using it], I lost the ability to finalize my selection with the 'Enter' key:
    class CustomInputDialog {
         public static javax.swing.JLabel lbl;
         public static javax.swing.JTextField txt;
         public static javax.swing.JPopupMenu pop;
         public static String showInputDialog(String message, String guess) {
              lbl = new javax.swing.JLabel(message);
              txt = new javax.swing.JTextField(guess, 10);
              pop = new javax.swing.JPopupMenu();
              javax.swing.Action copyAction = new javax.swing.AbstractAction(javax.swing.text.DefaultEditorKit.copyAction) {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        txt.copy();
              javax.swing.Action cutAction = new javax.swing.AbstractAction(javax.swing.text.DefaultEditorKit.cutAction) {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        txt.cut();
              javax.swing.Action pasteAction = new javax.swing.AbstractAction(javax.swing.text.DefaultEditorKit.pasteAction) {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        txt.paste();
              javax.swing.JMenuItem m1 = new javax.swing.JMenuItem(copyAction);
              javax.swing.JMenuItem m2 = new javax.swing.JMenuItem(cutAction);
              javax.swing.JMenuItem m3 = new javax.swing.JMenuItem(pasteAction);
              m1.setText("Copy"); m2.setText("Cut"); m3.setText("Paste");
              pop.add(m1); pop.add(m2); pop.add(m3);
              txt.setComponentPopupMenu(pop);
              java.awt.Container ct = new java.awt.Container();
              ct.setLayout(new java.awt.GridLayout(2,1));
              ct.add(lbl); ct.add(txt); txt.selectAll();
              Object[] options = {"OK", "Cancel"};
              int responce = javax.swing.JOptionPane.showOptionDialog(null, ct, "TITLE.", javax.swing.JOptionPane.OK_CANCEL_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE, null, options, txt);
              if (responce == javax.swing.JOptionPane.OK_OPTION) {
                   return txt.getText();
              return null;
    }In an attempt to get the enter key working, I separated an instance of the JOptionPane class, so I could refer to it in a keyHandler event using the JTextField. In doing the following code adjustments, now not only does the enter key do nothing, but the method seems to always return null, even if the OK button is selected by the user via mouse:
    class CustomInputDialog {
         public static javax.swing.JLabel lbl;
         public static javax.swing.JTextField txt;
         public static javax.swing.JPopupMenu pop;
         public static javax.swing.JOptionPane op;
         public static String showInputDialog(String message, String guess) {
              lbl = new javax.swing.JLabel(message);
              txt = new javax.swing.JTextField(guess, 10);
              pop = new javax.swing.JPopupMenu();
              javax.swing.Action copyAction = new javax.swing.AbstractAction(javax.swing.text.DefaultEditorKit.copyAction) {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        txt.copy();
              javax.swing.Action cutAction = new javax.swing.AbstractAction(javax.swing.text.DefaultEditorKit.cutAction) {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        txt.cut();
              javax.swing.Action pasteAction = new javax.swing.AbstractAction(javax.swing.text.DefaultEditorKit.pasteAction) {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        txt.paste();
              javax.swing.JMenuItem m1 = new javax.swing.JMenuItem(copyAction);
              javax.swing.JMenuItem m2 = new javax.swing.JMenuItem(cutAction);
              javax.swing.JMenuItem m3 = new javax.swing.JMenuItem(pasteAction);
              m1.setText("Copy"); m2.setText("Cut"); m3.setText("Paste");
              pop.add(m1); pop.add(m2); pop.add(m3);
              txt.setComponentPopupMenu(pop);
              txt.addKeyListener(new java.awt.event.KeyListener() {
                   @Override public void keyTyped(java.awt.event.KeyEvent e) {}
                   @Override public void keyReleased(java.awt.event.KeyEvent e) {}
                   @Override public void keyPressed(java.awt.event.KeyEvent e) {
                        if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
                             op.setInitialValue(javax.swing.JOptionPane.OK_OPTION);
                             op.selectInitialValue();
              java.awt.Container ct = new java.awt.Container();
              ct.setLayout(new java.awt.GridLayout(2,1));
              ct.add(lbl); ct.add(txt); txt.selectAll();
              Object[] options = {"OK", "Cancel"};
              op = new javax.swing.JOptionPane(ct, javax.swing.JOptionPane.QUESTION_MESSAGE, javax.swing.JOptionPane.OK_CANCEL_OPTION, null, options, txt);
              op.createDialog(null, "TITLE.").setVisible(true);
              int returnValue = (op.getValue() instanceof Integer) ? ((Integer)op.getValue()).intValue() : javax.swing.JOptionPane.CANCEL_OPTION;
              if (returnValue == javax.swing.JOptionPane.OK_OPTION) {
                   return txt.getText();
              return null;
    }I've been going through the javax.swing references on the APIs, but I cannot find anything that seems to make sense to me as to a way to work towards the solution, if anyone could give me some help or guidance, it would be much appreciated. Thanks!
    Ps: I think the issue may be in "returnValue" getting set to JOptionPane.CANCEL_OPTION as it is being executed before the JOptionPane dialog is finally closed and a value is entered. However, on the examples I was looking at, it didn't seem like there was an onClosed event handler or something similar used.
    Pps [note]: I originally posted this in the Java Programming area, and was directed to come here. Original Post: [http://forums.sun.com/thread.jspa?threadID=5445202|http://forums.sun.com/thread.jspa?threadID=5445202].

    EDIT: I finally was able to get everything working the way I want it. Thanks for everyone's help. If anyone would like to use my code in the future, I'll attach it to this post. Note: For new lines, I had to use the <html> tag at the start of the msg and <br> tags for new lines instead of using the \r\n characters.
    class CustomInputDialog {
         public static javax.swing.JLabel lbl;
         public static javax.swing.JTextField txt;
         public static javax.swing.JPopupMenu pop;
         public static javax.swing.JButton ok_button, cancel_button;
         public static javax.swing.JDialog optionWindow;
         public static String returnValue = null;
         public static String showInputDialog(String title, String message, String guess) {
              CustomInputDialog.returnValue = null;
              Object[] options = {"OK", "Cancel"};
              lbl = new javax.swing.JLabel(message); txt = new javax.swing.JTextField(guess, 40);
              txt.addKeyListener(new java.awt.event.KeyListener() {
                   @Override public void keyTyped(java.awt.event.KeyEvent evt) {}
                   @Override public void keyReleased(java.awt.event.KeyEvent evt) {}
                   @Override public void keyPressed(java.awt.event.KeyEvent evt) {
                        if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
                             ok_button.doClick();
                        else if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) {
                             cancel_button.doClick();
              ok_button = new javax.swing.JButton((String)options[0]); cancel_button = new javax.swing.JButton((String)options[1]);
              ok_button.addActionListener(new java.awt.event.ActionListener() {
                   public void actionPerformed(java.awt.event.ActionEvent evt) {
                        CustomInputDialog.returnValue = txt.getText();
                        optionWindow.dispose();
              cancel_button.addActionListener(new java.awt.event.ActionListener() {
                   public void actionPerformed(java.awt.event.ActionEvent evt) {
                        optionWindow.dispose();
              pop = new javax.swing.JPopupMenu();
              javax.swing.JMenuItem m1 = new javax.swing.JMenuItem(new javax.swing.AbstractAction(javax.swing.text.DefaultEditorKit.copyAction) {
                   public void actionPerformed(java.awt.event.ActionEvent evt) {
                        txt.copy();
              }); m1.setText("Copy");
              javax.swing.JMenuItem m2 = new javax.swing.JMenuItem(new javax.swing.AbstractAction(javax.swing.text.DefaultEditorKit.cutAction) {
                   public void actionPerformed(java.awt.event.ActionEvent evt) {
                        txt.cut();
              }); m2.setText("Cut");
              javax.swing.JMenuItem m3 = new javax.swing.JMenuItem(new javax.swing.AbstractAction(javax.swing.text.DefaultEditorKit.pasteAction) {
                   public void actionPerformed(java.awt.event.ActionEvent evt) {
                        txt.paste();
              }); m3.setText("Paste");
              pop.add(m1); pop.add(m2); pop.add(m3);
              txt.setComponentPopupMenu(pop);
              java.awt.Container text_container = new java.awt.Container();
              text_container.setLayout(new java.awt.FlowLayout());
              text_container.add(txt);
              java.awt.Container button_container = new java.awt.Container();
              button_container.setLayout(new java.awt.FlowLayout());
              button_container.add(ok_button); button_container.add(cancel_button);
              java.awt.Container ct = new java.awt.Container();
              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(ct);
              layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(lbl).addContainerGap())
                   .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(text_container).addContainerGap())
                   .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(button_container).addContainerGap())
              layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lbl)
                        .addContainerGap()
                        .addComponent(text_container)
                        .addContainerGap()
                        .addComponent(button_container)
                        .addContainerGap()
              ct.setLayout(layout);
              optionWindow = new javax.swing.JDialog((javax.swing.JFrame)null, title, true);
              optionWindow.setContentPane(ct); txt.selectAll();
              optionWindow.pack();
              optionWindow.setResizable(false);
              java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(), size = optionWindow.getSize();
              optionWindow.setLocation((screenSize.width-size.width)/2, (screenSize.height-size.height)/2);
              optionWindow.setVisible(true);
              return CustomInputDialog.returnValue;
    public class customDialogTestApp {
         public static void main(String[] args) {
              String ex = "<html><p>This is a really long group of text,<br>";
              ex += "The goal of this text group is to show that new lines seem to not be working<br>";
              ex += "properly with the customDialog class that I wrote up.<br>";
              ex += "However input right-clicking and [enter] key functionality in the text field now works fine<br>";
              ex += "as you can probably see in the textfield below this message.<br><br>";
              ex += "Thanks for your time and help in this manner!";
              String returnVal = CustomInputDialog.showInputDialog("Custom Dialog Test Application", ex, "NOTE: This time the label text is being passed with HTML formatting in a <p> tag, using '<br>' for linebreaks as opposed to '\r\n'.");
    }Thanks to everyone who had helped me!
    Edited by: xel614 on Jul 21, 2010 11:34 AM

  • Resize JComboBox dropdown doesn't work without customized ListCellRenderer

    Based on the forum thread Horizontal scrollbar for JComboBox across multiple look and feel , the following code will work, if only I provide a customized ListCellRenderer (A JPanel with several JLabels).
    FYI, here is my ListCellRenderer code [http://jstock.cvs.sourceforge.net/viewvc/jstock/jstock/src/org/yccheok/jstock/gui/ResultSetCellRenderer.java?view=markup]
    Here is the code which adjust the drop down list width. The setup instruction is exactly same as the one mentioned in forum by Kleopatra
        private void adjustPopupWidth() {
            if (this.getItemCount() == 0) return;
            Object comp = this.getUI().getAccessibleChild(this, 0);
            if (!(comp instanceof JPopupMenu)) {
                return;
            JPopupMenu popup = (JPopupMenu) comp;
            JScrollPane scrollPane = (JScrollPane) popup.getComponent(0);
            Object value = this.getItemAt(0);
            Component rendererComp = this.getRenderer().getListCellRendererComponent(null, value, 0, false, false);       
            if (rendererComp instanceof JXTable) {
                scrollPane.setColumnHeaderView(((JTable) rendererComp).getTableHeader());
            Dimension prefSize = rendererComp.getPreferredSize();
            Dimension size = scrollPane.getPreferredSize();
            size.width = Math.max(size.width, prefSize.width);
            scrollPane.setPreferredSize(size);
            scrollPane.setMaximumSize(size);
            scrollPane.revalidate();
        }However, when come to a JComboBox, without explicitly provided it a list cell renderer, the above code will have NPE being thrown at line
           Component rendererComp = this.getRenderer().getListCellRendererComponent(null, value, 0, false, false);
           // Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
           // at javax.swing.plaf.basic.BasicComboBoxRenderer.getListCellRendererComponent(BasicComboBoxRenderer.java:94)Hence, I modify the code as follow and hoping it will work.
        private void adjustPopupWidth() {
            if (this.getItemCount() == 0) return;
            Object comp = this.getUI().getAccessibleChild(this, 0);
            if (!(comp instanceof JPopupMenu)) {
                return;
            JPopupMenu popup = (JPopupMenu) comp;
            JScrollPane scrollPane = (JScrollPane) popup.getComponent(0);
            Object value = this.getItemAt(0);
            //Component rendererComp = this.getRenderer().getListCellRendererComponent(null, value, 0, false, false);
            Component rendererComp = this.getRenderer().getListCellRendererComponent((JList)scrollPane.getViewport().getView(), value, 0, false, false);       
            if (rendererComp instanceof JXTable) {
                scrollPane.setColumnHeaderView(((JTable) rendererComp).getTableHeader());
            Dimension prefSize = rendererComp.getPreferredSize();
            Dimension size = scrollPane.getPreferredSize();
            size.width = Math.max(size.width, prefSize.width);
            scrollPane.setPreferredSize(size);
            scrollPane.setMaximumSize(size);
            scrollPane.revalidate();
        }No more exception being thrown this time. Just that my dropdown list doesn't resize at all when I have a long String. It remains normal size as usual, with horizontal scrollbar being shown to catter the long String.
    Is there anything I had missed out?
    Thanks
    Edited by: yccheok on Oct 23, 2010 9:40 PM
    Edited by: yccheok on Oct 23, 2010 9:41 PM

    Yes. The problem solved. Out of curiosity, is it necessary to have statement? As I remove it, it just work as well.
    scrollPane.revalidate();I include SSCCE for this problem.
    package sandbox;
    import java.awt.Component;
    import java.awt.Dimension;
    import javax.swing.JList;
    import javax.swing.JPopupMenu;
    import javax.swing.JScrollPane;
    import javax.swing.plaf.basic.BasicComboPopup;
    * @author yccheok
    public class NewJFrame extends javax.swing.JFrame {
        /** Creates new form NewJFrame */
        public NewJFrame() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jComboBox1 = new javax.swing.JComboBox();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            getContentPane().setLayout(new java.awt.FlowLayout());
            jComboBox1.setEditable(true);
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Long Long Long Long Item 4" }));
            jComboBox1.setPreferredSize(new java.awt.Dimension(80, 20));
            jComboBox1.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
                public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
                public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                    jComboBox1PopupMenuWillBecomeVisible(evt);
            getContentPane().add(jComboBox1);
            pack();
        }// </editor-fold>
        private void jComboBox1PopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            adjustPopupWidth();
        * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        private void adjustPopupWidth() {
            if (jComboBox1.getItemCount() == 0) return;
            Object comp = jComboBox1.getUI().getAccessibleChild(jComboBox1, 0);
            if (!(comp instanceof JPopupMenu)) {
                return;
            JPopupMenu popup = (JPopupMenu) comp;
            JScrollPane scrollPane = (JScrollPane) popup.getComponent(0);
            Object value = jComboBox1.getItemAt(0);
            Component rendererComp = jComboBox1.getRenderer().getListCellRendererComponent((JList)scrollPane.getViewport().getView(), value, 0, false, false);
            //if (rendererComp instanceof JXTable) {
            //    scrollPane.setColumnHeaderView(((JTable) rendererComp).getTableHeader());
            //Dimension prefSize = rendererComp.getPreferredSize();
            BasicComboPopup basic = (BasicComboPopup)comp;
            Dimension prefSize = basic.getList().getPreferredSize();
            Dimension size = scrollPane.getPreferredSize();
            size.width = Math.max(size.width, prefSize.width);
            scrollPane.setPreferredSize(size);
            scrollPane.setMaximumSize(size);
            //scrollPane.revalidate();
        // Variables declaration - do not modify
        private javax.swing.JComboBox jComboBox1;
        // End of variables declaration
    }

  • Custom JComboBox -- MouseListener

    Hi. I'm in the process of making a custom JComboBox (called TitledComboBox).
    It's going to use a ComboBox as the component that is always visible, but when you click it instead of the standard dropdown, I'm creating a JPopupMenu to replace that. That way I want to avoid the first element (or the selected one) being repeated inside the list.
    So I've created my class extending JComboBox, and implemented MouseListener, but I'm unable to make the listener work for the JComboBox layout manager. It works perfectly for the spots on the JComboBox where the LayoutManager doesnt paint (or whatever it does), so the "arrow" doesn't effect the MouseListener....
    How can I extend the default JComboBox LayoutManager to have the same MouseListener??

    package gui;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.*;
    @SuppressWarnings("serial")
    public class TitledComboBox extends JComboBox implements MouseListener
        @SuppressWarnings("serial")
        private class PopItem extends JMenuItem
             public PopItem(String text)
                setLayout(null);
                setText(text);
                setOpaque(false);
                setBackground(Color.BLACK);
            public void paint(Graphics g)
                super.paint(g);
        @SuppressWarnings("serial")
        private class PopMenu extends JPopupMenu
              public PopMenu()
                   this.setLayout(null);
                   this.setPopupSize(120, 23*this.getComponentCount());
                   this.setOpaque(false);
              public PopMenu(String[] items)
                   this();
                   for(int i = 0; i < items.length; i++)
                        this.add(new PopItem(items));
                   updateSize();
              private void updateSize()
                   this.setPopupSize(120, 23*this.getComponentCount());
              public void show(Component arg0, int arg1, int arg2)
                   super.show(arg0, arg1, arg2);
                   this.setVisible(true);
              public void paint(Graphics g)
                   super.paint(g);
         public PopMenu dropdown;
         private TitledComboBox()
              super();
              this.addMouseListener(this);
              this.setVisible(true);
    this.setEnabled(false);
         public TitledComboBox(String title)
              this();
              this.addItem(title);
              dropdown = new PopMenu();
         public TitledComboBox(String title, String[] items)
              this();
              this.addItem(title);
              dropdown = new PopMenu(items);
         public void addPopItem(String item)
              dropdown.add(new PopItem(item));
              dropdown.updateSize();
         public void removePopItem(int itemIndex)
              dropdown.remove(itemIndex);
              dropdown.updateSize();
         public void paint(Graphics g)
              this.setEnabled(true);
              super.paint(g);
              this.setEnabled(false);
         public void mouseClicked(MouseEvent m)
    dropdown.show(this, 0, 20);
         public void mouseEntered(MouseEvent arg0)
         public void mouseExited(MouseEvent arg0)
         public void mousePressed(MouseEvent arg0)
         public void mouseReleased(MouseEvent arg0)
    Using this now gives something very similar to a JComboBox, just without the top element showing. However, I STILL don't know how to get the LayoutManager to be a part of the MouseListener... Please help!
    Edited by: Ondkloss on Nov 21, 2007 7:12 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Implementing a dynamic Scrollable JPopupMenu

    Hi,
    I wanna make a scrollable JPopupMenu. What I am looking for is I am making a custom popup Menu which extends JPopupMenu. I would be overriding the add method.
    I dont want to add a list or a combo box to my JPopupMenu. I want to change the layout itself .. i.e. there is a function in the Container.class which gets called when we try to add a menuitem dynamically to the JPopupMenu
    Function Name:
    protected void addImpl(Component comp, Object constraints, int index)Snippet which i am looking in the function
    if (layoutMgr instanceof LayoutManager2) {
    ((LayoutManager2)layoutMgr).addLayoutComponent(comp, constraints);
              }Is there a way while addiing menu items dynamically that I can set the layout to scrollable and hence the menuitems when added are in a scrollpane automatically.. Hence I what i get also is a Scrollable JPopupMenu

    well, this is implementation of PopupMenu with scroll
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GraphicsConfiguration;
    import java.awt.GridLayout;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JPopupMenu;
    import javax.swing.JScrollPane;
    import javax.swing.JSeparator;
    public class ScrollPopupMenu extends JPopupMenu {
         private static final long serialVersionUID = 1L;
         private JPanel panelMenus = null;
         private JScrollPane scroll = null;
         public ScrollPopupMenu(GraphicsConfiguration gc) {
              super();
              scroll = new JScrollPane();
              panelMenus = new JPanel();
              panelMenus.setLayout(new GridLayout(0,1));
              scroll.setViewportView(panelMenus);
              scroll.setBorder(null);
              scroll.setMaximumSize(new Dimension(scroll.getMaximumSize().width,
                        this.getToolkit().getScreenSize().height -
                        this.getToolkit().getScreenInsets(gc).top -
                        this.getToolkit().getScreenInsets(gc).bottom - 4));
              super.add(scroll);
         public void show(Component invoker, int x, int y) {
              this.pack();
              panelMenus.validate();
              int maxsize = scroll.getMaximumSize().height;
              int realsize = panelMenus.getPreferredSize().height;
              int sizescroll = 0;
              if (maxsize < realsize) {
                   sizescroll = scroll.getVerticalScrollBar().getPreferredSize().width;
              scroll.setPreferredSize(new Dimension(
                        scroll.getPreferredSize().width + sizescroll,
                        scroll.getPreferredSize().height));
              super.show(invoker, x, y);
         public void add(JButton menuItem) {
              panelMenus.add(menuItem);
         public void addSeparator() {
              panelMenus.add(new JSeparator());
    }It is very basic, but this to help you, If you want to test, you compile this class:
    import javax.swing.SwingUtilities;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JTextField;
    import javax.swing.JLabel;
    public class FramePopupMenu extends JFrame {
         private static final long serialVersionUID = 1L;
         private JPanel jContentPane = null;
         private JButton btnPopup = null;
         private JTextField txtNumElem = null;
         private JLabel lblNumElem = null;
         private JButton getBtnPopup() {
              if (btnPopup == null) {
                   btnPopup = new JButton();
                   btnPopup.setText("Ver men� popup");
                   btnPopup.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             ScrollPopupMenu mnu = new ScrollPopupMenu(FramePopupMenu.this.getGraphicsConfiguration());
                             int n = Integer.parseInt(getTxtNumElem().getText());
                             for (int i=0;i<n;i++)
                                  mnu.add(new JButton("Men� " + (i+1)));
                             mnu.show(btnPopup, btnPopup.getWidth(), 0);
              return btnPopup;
         private JTextField getTxtNumElem() {
              if (txtNumElem == null) {
                   txtNumElem = new JTextField();
                   txtNumElem.setColumns(3);
                   txtNumElem.setText("60");
              return txtNumElem;
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        FramePopupMenu thisClass = new FramePopupMenu();
                        thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        thisClass.setVisible(true);
         public FramePopupMenu() {
              super();
              initialize();
         private void initialize() {
              this.setSize(274, 109);
              this.setContentPane(getJContentPane());
              this.setTitle("Scroll en un men� popup");
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   lblNumElem = new JLabel();
                   lblNumElem.setText("N�mero de elementos del Men�");
                   FlowLayout flowLayout = new FlowLayout();
                   flowLayout.setHgap(8);
                   flowLayout.setVgap(8);
                   jContentPane = new JPanel();
                   jContentPane.setLayout(flowLayout);
                   jContentPane.add(getBtnPopup(), null);
                   jContentPane.add(lblNumElem, null);
                   jContentPane.add(getTxtNumElem(), null);
              return jContentPane;
    }

  • Custom purchase requsitionto vendor open and cleared payment report

    dear all i develop report but i cant ableto show in that open amount and cleared amount of vender in that report so please see this report and feedback me for logic to show open and clear amount of vendor purchase orderwise or vendorwise
    report zpo_purchase_history no standard page heading message-id 00.
    TABLES : bsik, bsak, lfa1, lfb1, skb1, t001, bapifvdexp_vzzbepp.
    type-pools:slis,ICON.
    types :begin of ty_po,
            banfn type eban-banfn,
            "Purchase Requisition Number
            bnfpo type eban-bnfpo,
            "Item Number of Purchase Requisition
            ekgrp type eban-ekgrp,                 "Purchasing Group
            badat type eban-badat,
            "Requisition (Request) Date
            menge type eban-menge,
            KNTTP TYPE EBAN-KNTTP,
             PSTYP type eban-PSTYP,
            "Purchase Requisition Quantity
            meins type eban-meins,
            "Purchase Requisition Unit of Measure
            lifnr type ekko-lifnr,                 "Vendor Account Number
            bedat type ekko-bedat,                 "Purchasing Document Date
            ebeln type ekpo-ebeln,
            "Purchasing Document Number
            ebelp type ekpo-ebelp,
            "Item Number of Purchasing Document
            matkl type ekpo-matkl,                 "Material Group
            mtart type ekpo-mtart,                 "Material Type
            matnr type ekpo-matnr,                 "Material Number
            txz01 type ekpo-txz01,                 "Short Text
            menge1 type ekpo-menge,                "Purchase Order Quantity
            meins1 type ekpo-meins,
            "Purchase Order Unit of Measure
            balqty type ekpo-menge,                "Balance Quantity
            netpr type ekpo-netpr,
            "Net Price in Purchasing Document
            peinh type ekpo-peinh,                 "Price Unit
            mblnr type mseg-mblnr,
            "Number of Material Document
            zeile type mseg-zeile,                 "Item in Material Document
            menge2 type mseg-menge,                "GR Quantity
            meins2 type mseg-meins,                "GR Unit of Measure
            werks type mseg-werks,                 "Plant
            charg type mseg-charg,                 "Batch
            belnr type rbkp-belnr,
            "Document Number of an Invoice Document
            bldat type ekbe-bldat,                 "Document Date in Document
            belnr_b type rbkp-belnr,
            SHKZG type ekbe-SHKZG ,                "Debit/Credit Indicator
            DMBTR type   bsik-dmbtr,                "Amount in Local Currency
            DMBTR_C type   bsAk-dmbtr,                "Amount in Local Currency
            thick(10) type c,                      "Thickness
            width(10) type c,                      "Width
            length(10) type c,                     "Length
            grade(10) type c,                        "Grade
            BELNR_d type bseg-belnr,
            xblnr type bkpf-xblnr,
            awkey  type bkpf-awkey,
            RMWWR type rbkp-RMWWR,
            WMWST1 type rbkp-WMWST1,
            end of ty_po.
    types :begin of ty_ekko,
            ebeln type ekko-ebeln,
            lifnr type ekko-lifnr,
            bedat type ekko-bedat,
            end of ty_ekko.
    types:begin of ty_ekpo,
            ebeln type ekpo-ebeln,
            ebelp type ekpo-ebelp,
            matnr type ekpo-matnr,
            txz01 type ekpo-txz01,
            menge type ekpo-menge,
            meins type ekpo-meins,
            netpr type ekpo-netpr,
            peinh type ekpo-peinh,
            banfn type ekpo-banfn,
            bnfpo type ekpo-bnfpo,
            mtart type ekpo-mtart,
            end of ty_ekpo.
    types :begin of ty_eban,
            banfn type eban-banfn,
            bnfpo type eban-bnfpo,
            matnr type eban-matnr,
            menge type eban-menge,
            meins type eban-meins,
            end of ty_eban.
    types : begin of ty_ekbe,
             ebeln type ekbe-ebeln,
             ebelp type ekbe-ebelp,
             belnr type ekbe-belnr,
             bldat type ekbe-bldat,
             gjahr type ekbe-gjahr,
             buzei type ekbe-buzei,
             matnr type ekbe-matnr,
             DMBTR type ekbe-dmbtr,
             shkzg type ekbe-shkzg,
             end of ty_ekbe.
    types : begin of ty_mseg,
             mblnr type mseg-mblnr,
             mjahr type mseg-mjahr,
             zeile type mseg-zeile,
             menge type mseg-menge,
             meins type mseg-meins,
             ebeln type mseg-ebeln,
             ebelp type mseg-ebelp,
             matnr type mseg-matnr,
             werks type mseg-werks,
             charg type mseg-charg,
             end of ty_mseg.
    types : begin of ty_rbkp,
             belnr type rbkp-belnr,
             gjahr type rbkp-gjahr,
             bldat type rbkp-bldat,
             lifnr type rbkp-lifnr,
             ZUONR type rbkp-ZUONR,
             RMWWR type rbkp-RMWWR,
             WMWST1 type rbkp-WMWST1,
             end of ty_rbkp.
    types : begin of ty_bseg,
             bukrs type bseg-bukrs,
             belnr type bseg-belnr,
             gjahr type bseg-gjahr,
             buzei type bseg-buzei,
             valut type bseg-valut,
             wrbtr type bseg-wrbtr ,
             augbl type bseg-augbl,
             matnr type bseg-matnr,
             lifnr type bseg-lifnr,
             ebeln type bseg-ebeln,
             end of ty_bseg.
    types : begin of ty_rseg,
             belnr type rseg-belnr,
             gjahr type rseg-gjahr,
             ebeln type rseg-ebeln,
             ebelp type rseg-ebelp,
             matnr type rseg-matnr,
             bukrs type rseg-bukrs,
             end of ty_rseg.
    types : begin of ty_bsik,
             belnr type bsik-belnr,
              buzei type bsik-buzei,
             DMBTR type bsik-DMBTR,
             budat type bsik-budat,
             shkzg type bsik-shkzg,
             ebeln type bsik-ebeln,
             lifnr type bsik-lifnr,
             end of ty_bsik.
    types : begin of ty_bsak,
             belnr type bsak-belnr,
       lifnr type bsak-lifnr,
        ebeln type bsak-ebeln,
             DMBTR_C type bsak-DMBTR,
    ZUONR type bsak-ZUONR,
             end of ty_bsak.
    types: begin of ty_bkpf,
             BELNR type bkpf-belnr,
             xblnr type bkpf-xblnr,
             awkey  type bkpf-awkey,
           end of ty_bkpf.
    data: it_po type standard table of ty_po,
           it_ekko type standard table of ty_ekko,
           it_ekpo type standard table of ty_ekpo,
           it_eban type standard table of ty_eban,
           it_ekbe type standard table of ty_ekbe,
           it_mseg type standard table of ty_mseg,
           it_rbkp type standard table of ty_rbkp,
           it_rseg type standard table of ty_rseg,
           it_bseg type standard table of ty_bseg,
           it_bsik type STANDARD TABLE OF ty_bsik with header line,
           it_bsak type STANDARD TABLE OF ty_bsak,
           it_bkpf type standard table of ty_bkpf,
           wa_po type ty_po,
           wa_ekko type ty_ekko,
           wa_ekpo type ty_ekpo,
           wa_eban type ty_eban,
           wa_mseg type ty_mseg,
           wa_rbkp type ty_rbkp,
           wa_rseg type ty_rseg,
           wa_bseg type ty_bseg,
           wa_ekbe type ty_ekbe,
           wa_bsik type ty_bsik,
           wa_bsak type ty_bsak,
           wa_bkpf type ty_bkpf.
    data: it_fcat type slis_t_fieldcat_alv,
           it_lshead type slis_t_listheader,
           it_sort type slis_t_sortinfo_alv,
           wa_fcat type slis_fieldcat_alv,
           wa_lshead type slis_listheader,
           wa_layout type slis_layout_alv,
           wa_sort type slis_sortinfo_alv.
    data :it_cl_data like table of clobjdat,
           wa_cl_data like clobjdat.
    data: values(10) type n.
    data: value1(4) type N.
    data: c_matkl type ekpo-matkl,
           c_matnr type ekpo-matnr,
           c_ekgrp type eban-ekgrp,
           c_badat type eban-badat,
           c_index type sy-tabix,
           c_grmenge type mseg-erfmg,
           c_low(10) type c,
           c_high(10) type c,
           c_date type string,
           c_bukrs type ekko-bukrs,
           c_WERKS type eban-WERKS.
    data: gd_date(10).
    DATA: V_EVENTS TYPE SLIS_T_EVENT,
           WA_EVENT TYPE SLIS_ALV_EVENT.
    *********Selection screen variables*********
    selection-screen:begin of block b1 with frame title text-001.
    select-options: s_bukrs for c_bukrs DEFAULT  'bmp1',
                     s_WERKS for c_WERKS,
                     s_matnr for c_matnr DEFAULT 'rm-01',
                     s_matkl for c_matkl ,
                     s_badat for c_badat ,"obligatory,
                     s_ekgrp for c_ekgrp.
    parameters: ch_bal as checkbox.
    selection-screen:end of block b1.
    *initialization.
    * PERFORM EVENT_CALL.
    *  PERFORM POPULATE_EVENT.
    start-of-selection.
         PERFORM EVENT_CALL.
       PERFORM POPULATE_EVENT.
       perform getdata.
       perform setdata.
       perform fieldcat.
       perform display.
    *&      Form  GETDATA
    form getdata .
       select a~BANFN
              a~bnfpo
              a~ekgrp
              a~badat
              a~KNTTP
              a~PSTYP
              b~ebeln
              b~ebelp
              b~matkl
              b~matnr
              b~bukrs
              into corresponding fields of table it_po
              from eban as a inner join ekpo as b
              on a~banfn = b~banfn and
                 a~bnfpo = b~bnfpo AND
                 A~KNTTP = B~KNTTP and
                 a~PSTYP = b~PSTYP
              where  a~badat in s_badat and
                     a~ekgrp in s_ekgrp and
                     a~WERKS in s_WERKS and
                     b~matnr in s_matnr and
                     b~matkl in s_matkl and
                     b~bukrs in s_bukrs and
                     b~loekz <> 'L' and
                     a~loekz <> 'X'.
       if it_po[] is not initial.
         select ebeln
                ebelp
                matnr
                txz01
                menge
                meins
                netpr
                peinh
                banfn
                bnfpo
                mtart
                from ekpo into table it_ekpo
                for all entries in it_po
                where ebeln = it_po-ebeln and
                      ebelp = it_po-ebelp and
                      loekz <> 'L'.
         select banfn
                bnfpo
                matnr
                menge
                meins
                from eban into table it_eban
                for all entries in it_po
                where banfn = it_po-banfn and
                      bnfpo = it_po-bnfpo and
                      loekz <> 'X'.
         if it_ekpo[] is not initial.
           select ebeln
                  lifnr
                  bedat
                  from ekko into table it_ekko
                  for all entries in it_ekpo
                  where ebeln = it_ekpo-ebeln.
           select ebeln
                  ebelp
                  belnr
                  bldat
                  gjahr
                  buzei
                  matnr
                  DMBTR
                  shkzg
                  from ekbe into table it_ekbe
                  for all entries in it_ekpo
                  where ebeln = it_ekpo-ebeln and
                        ebelp = it_ekpo-ebelp .
    *if it_ekbe-shkzg = 'H'.
    **ekbe-dmbtr = ekbe-dmbtr * -1.
    **ekbe-menge = ekbe-menge * -1.
    *endif.
    * select belnr
    *             gjahr
    *             ebeln
    *             ebelp
    *     from bseg into table it_bseg
    *             for all entries in it_ekpo
    *             where ebeln = it_ekpo-ebeln and
    *                   ebelp = it_ekpo-ebelp.
           select belnr
                  gjahr
                  ebeln
                  ebelp
                  matnr
                  bukrs
                  from rseg into table it_rseg
                  for all entries in it_ekpo
                  where ebeln = it_ekpo-ebeln and
                        ebelp = it_ekpo-ebelp.
         endif.
         if it_ekbe[] is not initial.
           select mblnr
                  mjahr
                  zeile
                  menge
                  meins
                  ebeln
                  ebelp
                  matnr
                  werks
                  charg
                  from mseg into table it_mseg
                  for all entries in it_ekbe
                  where mblnr = it_ekbe-belnr and
                        mjahr = it_ekbe-gjahr and
                        zeile = it_ekbe-buzei and
                        bwart = '101'.
         endif.
         if it_rseg[] is not initial.
           select belnr
                  gjahr
                  bldat
                  lifnr
                  ZUONR
                  RMWWR
                  WMWST1
                  from rbkp into table it_rbkp
                  for all entries in it_rseg
                  where belnr = it_rseg-belnr.
         endif.
    *if it_rseg[] is not initial.
    *      SELECT bukrs
    *              belnr
    *              gjahr
    *              buzei
    *              valut
    *              wrbtr
    *              augbl
    *              matnr
    *              lifnr
    *              ebeln
    *        INTO TABLE it_bseg
    *          FROM bseg
    *          FOR ALL ENTRIES IN it_rseg
    *          WHERE bukrs = it_rseg-bukrs and ebeln = it_rseg-ebeln and mwskz = ''.
    *endif.
    *loop at it_BKPF into wa_BKPF.
    *  values = wa_rbkp-belnr.
    *  value1 = wa_rbkp-gjahr.
       data: aekey_1 type string .
    *CONCATENATE values value1 into aekey_1.
    *  if it_BSEG[] is not initial.
    *MESSAGE aekey_1 type 'I'.
           SELECT single belnr xblnr awkey into wa_bkpf
             from bkpf
             where awkey = aekey_1.
    SELECT SINGLe belnr
    buzei
    dmbtr
    budat
       shkzg
       ebeln
       lifnr
       FROM bsik
    INTO CORRESPONDING FIELDS OF  wa_bsik
    *FOR ALL ENTRIES IN it_bseg
    WHERE
        bukrs in s_bukrs and
        lifnr = wa_rbkp-lifnr
    and
    *AND gjahr = it_bseg-gjahr
    * AND
        belnr = wa_bkpf-belnr.
    insert wa_bsik into table it_bsik.
    CLEAR wa_bsik.
    CLEAR it_bsik.
    *endloop.
    * and ebeln = it_bseg-ebeln .
    *    select BELNR
    **           SHKZG
    **           DMBTR
    *           from bkpf into table it_bkpf
    *            for ALL ENTRIES IN it_rbkp
    *            where belnr = it_rbkp-belnr.
    *        ENDif.
    IF IT_bseg[] IS NOT INITIAL.
           select belnr
             LIFNR
             ebeln
                  DMBTR
              ZUONR
                  from bsik into table it_bsik
                  for all entries in it_bseg
                  where belnr = it_bseg-belnr.
           select belnr
             LIFNR
             ebeln
                  DMBTR
              ZUONR
                  from bsak into table it_bsak
                  for all entries in it_bseg
                  where belnr = it_bseg-belnr.
    ENDIF.
       else.
         message s002.
         leave list-processing.
       endif.
    endform.                    " GETDATA
    *&      Form  SETDATA
    form setdata .
       clear wa_po.
       loop at it_po into wa_po.
         c_index = sy-tabix.
    ********Calculate PR Quantity**********
         clear wa_eban.
         read table it_eban into wa_eban
                    with key banfn = wa_po-banfn
                             bnfpo = wa_po-bnfpo.
         if sy-subrc eq 0.
           move:wa_eban-menge to wa_po-menge,
                wa_eban-meins to wa_po-meins.
         endif.
    ********Calculate PO Quantity**********
         clear wa_ekpo.
         read table it_ekpo into wa_ekpo
                    with key banfn = wa_po-banfn
                             bnfpo = wa_po-bnfpo .
         if sy-subrc eq 0.
           move:wa_ekpo-txz01 to wa_po-txz01,
                wa_ekpo-netpr to wa_po-netpr,
                wa_ekpo-peinh to wa_po-peinh,
                wa_ekpo-mtart to wa_po-mtart,
                wa_ekpo-menge to wa_po-menge1,
                wa_ekpo-meins to wa_po-meins1.
         endif.
    ********Calculate Balance Quantity******
         clear wa_mseg.
         loop at it_mseg into wa_mseg
                where ebeln = wa_po-ebeln and
                      ebelp = wa_po-ebelp.
           c_grmenge = c_grmenge + wa_mseg-menge.
         endloop.
         move:wa_mseg-mblnr to wa_po-mblnr,
              c_grmenge to wa_po-menge2,
              wa_mseg-meins to wa_po-meins2,
              wa_mseg-werks to wa_po-werks,
              wa_mseg-charg to wa_po-charg.
         wa_po-balqty = wa_eban-menge - c_grmenge.
         clear : wa_rseg,wa_rbkp.
         read table it_rseg into wa_rseg with key
                        ebeln = wa_mseg-ebeln
                        ebelp = wa_mseg-ebelp.
         read table it_rbkp into wa_rbkp
                    with key belnr = wa_rseg-belnr
                             gjahr = wa_rseg-gjahr.
         if sy-subrc eq 0.
           move : wa_rbkp-belnr to wa_po-belnr,
                  wa_rbkp-bldat to wa_po-bldat,
                  wa_rbkp-RMWWR to wa_po-RMWWR,
                  WA_RBKP-WMWST1 TO WA_PO-WMWST1.
         endif.
           read table it_bseg into wa_bseg with key
                         ebeln = wa_rseg-ebeln
                         bukrs = wa_rseg-bukrs.
           if sy-subrc eq 0.
             move wa_bseg-belnr to wa_po-belnr_d.
           endif.
    *    read table it_bkpf into wa_bkpf
    *    with key belnr = wa_ekbe-belnr.
    *    read table it_bseg into wa_bseg
    *    with key belnr = wa_bkpf-belnr.
    CLEAR wa_bsik.
    clear it_bsik.
         read table it_bsik into wa_bsik
         with key belnr = wa_bkpf-belnr.
    *    if wa_bsik-shkzg = 'H'.
    *     wa_bsik-DMBTR = wa_bsik-DMBTR * 1.
    *     endif.
           if sy-subrc eq 0.
             move : wa_bsik-belnr to wa_po-belnr,
                     wa_bsik-DMBTR to wa_po-DMBTR.
            endif.
    *    clear wa_bsik.
    *    read table it_bsik into wa_bsik
    *               with key  belnr = wa_bseg-belnr.
    *    if sy-subrc eq 0.
    *        move : wa_bsik-DMBTR to wa_po-DMBTR.
    *    endif.
    *clear wa_bsak.
    *    read table it_bsak into wa_bsak
    *               with key  belnr = wa_bseg-belnr.
    *    if sy-subrc eq 0.
    *        move : wa_bsak-DMBTR_C to wa_po-DMBTR_C.
    *    endif.
    *clear : wa_rbkp.
    *loop at it_bsik into wa_bsik.
    *read table it_bsik into wa_bsik with key belnr = wa_rbkp-belnr.
    *if sy-subrc eq 0.
    *  move : wa_bsik-DMBTR to wa_po-DMBTR.
    *    endif.
    *endloop.
    *********Assign Vendor,PO Date*********
         clear wa_ekko.
         read table it_ekko into wa_ekko
                    with key ebeln = wa_po-ebeln.
         if sy-subrc eq 0.
           move:wa_ekko-lifnr to wa_po-lifnr,
                wa_ekko-bedat to wa_po-bedat.
         endif.
    *clear wa_ekko.
    *read table it_ekko into wa_ekko
    *with key lifnr = wa_po-lifnr.
    *if sy-subrc eq 0.
    *  move: wa_bsik-DMBTR to wa_po-DMBTR.
    *  endif.
    *    call function 'ZSD_BATCH_CLASSIFICATION_DATA'
    *      exporting
    **        ch_charg                   = wa_po-charg
    *        ch_matnr                   = wa_po-matnr
    *        ch_werks                   = wa_po-werks
    *      tables
    *        cl_data                    = it_cl_data
    **       I_SEL_CHARACTERISTIC       =
         loop at it_cl_data into wa_cl_data.
           if wa_cl_data-ausp1 ne '?'.
             if wa_cl_data-atnam eq 'THICKNESS'.
               move wa_cl_data-ausp1 to wa_po-thick.
             elseif wa_cl_data-atnam eq 'LENGTH'.
               move wa_cl_data-ausp1 to wa_po-length.
             elseif wa_cl_data-atnam eq 'WIDTH'.
               move wa_cl_data-ausp1 to wa_po-width.
             elseif wa_cl_data-atnam eq 'GRADE'.
               move wa_cl_data-ausp1 to wa_po-grade.
             endif.
           endif.
         endloop.
         modify it_po from wa_po index c_index.
         clear :c_grmenge,wa_po,wa_ekpo,wa_mseg,c_index.
       endloop.
    endform.                    " SETDATA
    *&      Form  FIELDCAT
    *       text
    *  -->  p1        text
    *  <--  p2        text
    form fieldcat .
       perform buildfields using '1' 'BANFN'  'IT_PO' 'PR Number' '' ''.
    *  perform buildfields using '2' 'BNFPO'  'IT_PO' 'PR Item Number' '' ''.
       perform  buildfields using '2' 'KNTTP' 'IT_PO' 'A/c Assignment Cat' '' ''.
       perform  buildfields using '2' 'PSTYP' 'IT_PO' 'Item Cat' '' ''.
       perform buildfields using '3' 'EKGRP'  'IT_PO' 'Purchase Group' '' ''.
       perform buildfields using '4' 'BADAT'  'IT_PO' 'Request Date' '' ''.
       perform buildfields using '5' 'MENGE'  'IT_PO' 'PR Quantity'  'X' ''.
       perform buildfields using '6' 'MEINS'  'IT_PO' 'PR Unit' '' ''.
       perform buildfields using '7' 'LIFNR'  'IT_PO' 'Vendor Number' '' ''.
       perform buildfields using '8' 'EBELN'  'IT_PO' 'Purchasing Doc No' '' ''  .
       perform buildfields using '9' 'BEDAT'  'IT_PO' 'PO Date' '' ''.
       perform buildfields using '10' 'MTART' 'IT_PO' 'Material Type' '' ''.
       perform buildfields using '11' 'MATKL' 'IT_PO' 'Material Group' '' ''.
       perform buildfields using '12' 'MATNR' 'IT_PO' 'Material Number' '' ''.
       perform buildfields using '13' 'TXZ01' 'IT_PO' 'Material Desc' '' ''.
       perform buildfields using '18' 'MENGE1' 'IT_PO' 'PO Quantity' 'X' ''.
       perform buildfields using '19' 'MEINS' 'IT_PO' 'PO Unit' '' ''.
       perform buildfields using '20' 'NETPR' 'IT_PO' 'Net Price' '' ''.
       perform buildfields using '21' 'PEINH' 'IT_PO' 'Price Unit' '' ''.
       perform buildfields using '22' 'MBLNR' 'IT_PO' 'GR Number' '' ''.
       perform buildfields using '23' 'MENGE2' 'IT_PO' 'GR Quantity' 'X' ''.
       perform buildfields using '24' 'MEINS2' 'IT_PO' 'GR Unit' '' ''.
       perform buildfields using '25' 'BELNR' 'IT_PO' 'Invoice doc. number' '' ''.
       perform buildfields using '26' 'BLDAT' 'IT_PO' 'Invoice Date' '' ''.
    *  perform buildfields using '26' 'BELNR_D' 'IT_POP' 'A/C Doc. No.' '' ''.
    *  perform buildfields using '26' 'AUGBL' 'IT_PO' 'Clearing Doc No.' '' ''.
       perform buildfields using '26' 'DMBTR' 'IT_PO' 'OPEN AMOUNT' '' ''.
      perform buildfields using '26' 'DMBTR' 'IT_PO' 'clear AMOUNT' '' ''.
    *  perform buildfields using '26' 'DMBTR_C' 'IT_PO' 'Clear balance' '' ''.
       if ch_bal = 'X'.
         perform buildfields using '27' 'BALQTY' 'IT_PO' 'Balance Quantity'
         'X' ''.
       endif.
       perform buildfields using '26' 'WMWST1' 'IT_PO' 'TOTAL TAX ADDED' 'X' ''.
       perform buildfields using '26' 'RMWWR' 'IT_PO' 'TOTAL AMOUNT IN INVOICE' 'X' ''.
    endform.                    " FIELDCAT
    *&      Form  BUILDFIELDS
    *       text
    *      -->P_0449   text
    *      -->P_0450   text
    *      -->P_0451   text
    *      -->P_0452   text
    form buildfields  using    value(p_col_pos) like sy-cucol
                                value(p_fldname) type slis_fieldname
                                value(p_tabname) type slis_tabname
                                value(p_reptext) like dd03p-reptext
                                value(p_do_sum) type char1
                                value(hotspot) type char1.
       wa_fcat-col_pos = p_col_pos.
       wa_fcat-fieldname = p_fldname.
       wa_fcat-tabname = p_tabname.
       wa_fcat-reptext_ddic = p_reptext.
       wa_fcat-do_sum = p_do_sum.
       wa_fcat-hotspot = hotspot.
       append wa_fcat to it_fcat.
       clear wa_fcat.
    endform.                    " BUILDFIELDS
    *&      Form  DISPLAY
    form display .
       clear wa_layout.
       wa_layout-zebra = 'X'.
       wa_layout-colwidth_optimize = 'X'.
    * wa_layout-box_fieldname     = 'SEL'.
    * wa_layout-edit = 'X'.
       perform build_sort using 'BANFN' '1' 'X'.
       call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
    *   I_INTERFACE_CHECK                 = ' '
    *   I_BYPASSING_BUFFER                = ' '
    *   I_BUFFER_ACTIVE                   = ' '
          i_callback_program               = sy-cprog
    *   I_CALLBACK_PF_STATUS_SET          = ' '
        I_CALLBACK_USER_COMMAND           = 'USER_COMMAND '
          i_callback_top_of_page           = 'TOP_OF_PAGE'
    *   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
    *   I_CALLBACK_HTML_END_OF_LIST       = ' '
    *   I_STRUCTURE_NAME                  =
        i_background_id                   = 'ALV_BACKGROUND'
    *   I_GRID_TITLE                      =
    *   I_GRID_SETTINGS                   =
          is_layout                        = wa_layout
          it_fieldcat                      = it_fcat
    *   IT_EXCLUDING                      =
    *   IT_SPECIAL_GROUPS                 =
         it_sort                           = it_sort
    *   IT_FILTER                         =
    *   IS_SEL_HIDE                       =
    *   I_DEFAULT                         = 'X'
        I_SAVE                            = 'A'
    *   IS_VARIANT                        =
    *   IT_EVENTS                         =
    *   IT_EVENT_EXIT                     =
    *   IS_PRINT                          =
    *   IS_REPREP_ID                      =
    *   I_SCREEN_START_COLUMN             = 0
    *   I_SCREEN_START_LINE               = 0
    *   I_SCREEN_END_COLUMN               = 0
    *   I_SCREEN_END_LINE                 = 0
    *   I_HTML_HEIGHT_TOP                 = 0
    *   I_HTML_HEIGHT_END                 = 0
    *   IT_ALV_GRAPHICS                   =
    *   IT_HYPERLINK                      =
    *   IT_ADD_FIELDCAT                   =
    *   IT_EXCEPT_QINFO                   =
    *   IR_SALV_FULLSCREEN_ADAPTER        =
    * IMPORTING
    *   E_EXIT_CAUSED_BY_CALLER           =
    *   ES_EXIT_CAUSED_BY_USER            =
         tables
           t_outtab                          = it_po[]
      exceptions
        program_error                     = 1
        others                            = 2
       if sy-subrc <> 0.
         message id sy-msgid type sy-msgty number sy-msgno
                 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       endif.
    endform.                    " DISPLAY
    *&      Form  top_of_page
    *       text
    form top_of_page.                                           "#EC *
    **********Create report header*********
       refresh it_lshead.
       clear wa_lshead.
    **********To display date in header*********
    *  write: s_badat-low to c_low dd/mm/yyyy,s_badat-high to c_high
    *  dd/mm/yyyy.
    *  if s_badat-high is initial.
    *    concatenate 'Dated on' c_low into c_date separated by space.
    *  else.
    *    concatenate 'Dated between' c_low 'and' c_high into c_date separated
    *    by space.
    *  endif.
       wa_lshead-typ = 'H'.
       wa_lshead-info = 'PR To Payment History'.
    *  'Pending Indents History -

    We had a requirement to retrieve "aging of receiveables" by customer. Basically, it goes thru each record and depending on the due date places the amounts in the following buckets (example). 0-30 day Overdue, 31-60 days Overdue, 61-90 days overdue, 30+ days overdue, 60+ days overdue) etc all the way to 6+ years overdue.
    There are also cooresponding buckets for coming due analysis. For example, what is: 0-30 days coming due, 31-60 days coming due, 30+ days coming due, etc...
    To do this, first I needed to be able be able to produce an open items statement at any given time in the past. Now, this seems impossible because of how the items go from open to cleared all the time. And an item that was open one month ago, may not be open anymore.
    What I did was first remove any selections on item status. Then compare the posting date with teh key date in the past, if the posting date is less than or equal to the key date, keep the record.
    Then compare the clearing date with the key date. First, keep all that are #. (This keeps all records still open from that posting date/key date)
    Then, add another check for all items that were cleared after the key date (GT Key Date). This gives you the open items on that date.
    Hope that makes sense. Let me know if you want clarification.
    /smw

  • Error in creation of custom PD infotype

    Hi,
    I have a task of creating a custom PD infotype(p9xxx). I created HRI9xxx structure with all the custom fields and when I try to create the infotype using tcode PPCI(selected 'field infotype' option and create button in the 'infotype' block was pressed), it gives an error message that p9xxx-begda is not in ABAP dictionary and then it gives me list of screens, module pools and tables created. This custom infotype entry does not exist in T777I. I have tried regenerating it and same problem persists. If anyone knows the solution, please do let me know.
    Thanks in advance

    Solved.

  • Implementing BADI MD_ADD_COL_EZPS for MD04 custom column

    Hi there,
    I'm using BADI MD_ADD_COL_EZPS to display 3 new buttons and three new columns in MD04.
    For each line item that is displayed, the custom column is filled, after the button is hit -This works fine.
    My Question is:
    Is there any way to limit the value that is filled into the new column so that it only appears on the FIRST line item/row?
    (At the moment it is repeated all the way down the page - the new value is a material characteristic, so doesn't change, will always be the same for each line)
    I've looked at all the available structures/tables in the FILL_ADD_COLUMNS method of the BADI, and none seem suitable
    to determine the "first" row. (ie. something like the way SY-TABIX or SY-INDEX might be used)
    Any help appreciated.
    Thanks,
    David.

    Hi Shubhendu,
    in the method 'ACTIVATE_ADD_COLUMNS', you can set the flag EZ1_MODE to '1' to make the first column visible always. (it's been a while, but I think setting it to '2' makes it visible when the button is pressed.)
    Same applies to EZ2_MODE for second column, EZ3_MODE for third.
    look at the flags/parameters in this method, and also in FILL_ADD_COLUMNS, to fill the data.
    here you need to fill structure EMDEZX_USEX1 (for column 1) etc.
    The code is hit for each record displayed in MD04
    Hopefully this helps you.
    Regards,
    David

  • Custom message required on log on pop-up in SAP CRM WEB UI

    We required custom message to the log- on popup, right now the message is coming after we give the user ID and password "starting SAP CRM" instead of that
    user required welcome message.., how can achieve this ?
    Please reply as soon as possible.

    Hi Pankaj,
    did you already check the guide in the CRM Wiki:
    https://wiki.sdn.sap.com/wiki/display/CRM/WelcomeUserMessageinWeb+UI
    Hope this answers your question.
    Best Regards,
    Michael

Maybe you are looking for