JCombox and F4  WindowsComboBoxUI   BasicComboBoxUI   KeyEvent.VK_F4

OK, I'm driving myself crazy with this one.
I have a JComboBox in an application. My application uses the F4 key to perform a specialized command. But, in the Windows L&F, the F4 key is mapped to open and close a popup menu if it has focus. So if the focus happens to be in the JComboBox field when f4 is hit, my command doesn't get run, and instead the popup comes up.
I've tried everything I can think of to disable the F4 on the popup, but nothing works. I've found the code that is handling the event. It
s in:
com.sun.java.swing.plaf.windows.WindowsComboBoxUI
but I can't find a way to get to it. Any suggestions are appreciated.

Jeanette, your the best. To answer your question, ttt means 'to the top'. I thought I'd push this one up on the board one more time to see if anyone had a solution.
Anyway... Your solution works.
I am familiar with InputMap/ActionMap, but I never tried the the WHEN_ANCESTOR_OF_FOCUSED_COMPONENT binding. I tried the WHEN_FOCUSED and WHEN_IN_FOCUSED_WINDOW, but I never thought to try the ancestor one for some reason. Anyway, you are correct, it is bound there. It is also bound to the parent input map, so you have to iterate through to get it as well. Here's the code that does it in case anyone else needs it. Thanks again for the help.
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0);
InputMap im = myCbox.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
while( im != null )
     im.remove(stroke);
     im = im.getParent();
}//while

Similar Messages

  • JMenus and ActionListeners

    I'm making a MineSweeper clone and need some pointers on how to let people start a new game by either going to Game and choosing new or Ctrl_N.
    Here is what I have so far:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    public class Menus extends JMenu
    private static TimerDisplay TD=new TimerDisplay();
    public static JMenuBar menus()
    JMenuBar mb=new JMenuBar();
    JMenu game=new JMenu("Game");
    game.setMnemonic(KeyEvent.VK_G);
    mb.add(game);
    JMenuItem nw=new JMenuItem("New");
    nw.setMnemonic(KeyEvent.VK_N);
    nw.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    nw.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent event)
    // What could I put here.
    JMenuItem exit=new JMenuItem("Exit");
    exit.setMnemonic(KeyEvent.VK_E);
    exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    exit.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent event)
    System.exit(0);
    game.add(nw);
    game.add(new JSeparator());
    game.add(exit);
    return mb;
    }

    I would probably opt for a different way of thinking about this. First off, I'd get rid of all of the statics there and make Menus a true OOP class. Next, I'd try to have it communicate in an OOP fashion with the class that displays and runs the game itself, here in my example called "MyGame". I'd give MyGame class an exit() method to allow it to decide how to exit, and a reset() method to allow it to decide how it wants to reset for a new game. This way the menus shouldn't have to and doesn't worry about these things. Something like so:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    public class Menus //extends JMenu
      private JMenuBar menubar = new JMenuBar();
      // a timerdisplay object may not be needed in the menu class
      //private TimerDisplay timerDisplay = new TimerDisplay();
      private MyGame myGame;
      Menus()
      //public void setGameDisplay(MyGame myGame, TimerDisplay timerDisplay)
      public void setGameDisplay(MyGame myGame)
        this.myGame = myGame;
        //this.timerDisplay = timerDisplay; // probably not needed
        initMenus();
      public JMenuBar getMenuBar()
        return menubar;
      public void initMenus()
        JMenu gameMenu = new JMenu("Game");
        gameMenu.setMnemonic(KeyEvent.VK_G);
        menubar.add(gameMenu);
        JMenuItem nw = new JMenuItem("New");
        nw.setMnemonic(KeyEvent.VK_N);
        nw.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
            ActionEvent.CTRL_MASK));
        nw.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent event)
            myGame.reset();
        JMenuItem exit = new JMenuItem("Exit");
        exit.setMnemonic(KeyEvent.VK_E);
        exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,
            ActionEvent.ALT_MASK));
        exit.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent event)
            //System.exit(0);
            myGame.exit();
        gameMenu.add(nw);
        gameMenu.add(new JSeparator());
        gameMenu.add(exit);
    }Then it could all be tied together with a Controller or Main class that creates the MyGame class, creates the Menus class and adds one to the other.

  • Switch JFrame setUndecorated On and Off, help

    i need to make a frame so that if the user hits f4 the frame decorations
    disappear.
    If i open the frame with setundecorated(true) the frame works fine.
    The same with the default setUndec(false).
    However it is unable to switch from one to the other.
    A jframe can only be undecorated when it is undispalayble.
    How do i make it undisplayable but displayed?
    If i call removeNotify() (the only way i know to make the frame
    undisplayable - otherwise setundec throws an error) the frame closes.
    Anyone have any suggestions? this is really important! thanks alot!

    Here's a slight modification. Notice I had to re-map action and keyStroke.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class UndecoratedFrameTest extends JFrame {
        private boolean unDecorated = false;
        private DecorateAction action;
        private JPanel mainPanel;
        public UndecoratedFrameTest() {
            action = new DecorateAction("Toggle");
            buildGUI();
        private void buildGUI() {
            mainPanel = (JPanel) getContentPane();
            mainPanel.setLayout(new BorderLayout());
            JPanel centerPanel = new JPanel();
            centerPanel.add(new JLabel("Center"));
            mainPanel.add(centerPanel, BorderLayout.CENTER);
            setUndecorated(unDecorated);
            JButton decButton = new JButton(action);
            mainPanel.add(decButton, BorderLayout.SOUTH);
            mainPanel.getActionMap().put("toggle", action);
            mainPanel.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0), "toggle");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
            setLocationRelativeTo(null);
        private void toggleDecoration() {
            dispose();
            setUndecorated(!unDecorated);
            mainPanel.getActionMap().put("toggle", action);
            mainPanel.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0), "toggle");
            setVisible(true);
            unDecorated = !unDecorated;
        public static void main(String[] args) {
            Runnable runnable = new Runnable() {
                public void run() {
                    UndecoratedFrameTest undecoratedFrameTest = new UndecoratedFrameTest();
                    undecoratedFrameTest.setVisible(true);
            SwingUtilities.invokeLater(runnable);
        private class DecorateAction extends AbstractAction {
            public DecorateAction(String name) {
                super(name);
            public void actionPerformed(ActionEvent e) {
                toggleDecoration();
    }Cheers
    DB

  • JButton method use BOF(Begin Of File) and EOF(End Of File) like VB?

    hii all friends :)
    I use Oracle Jdeveloper 10G to design with JClient Method.
    i want design navigation button use JButton(swing) not use JUNavigationBar.
    but i don,t understand how can i check last record and fist record like in Visual basic use Method BOF(Begin Of File) and EOF(End Of File)? What method/syntax in java i use it?
    Can u(all friend in comunity forum) help and teach me how?..
    Befors, thanks alot :)
    regards
    Fok Shen

    Thank,s kanad.
    I already try it, but method "isBeforeFirst" and "isAfterLast" not found in javax.swing.Jbutton.
    i used Oracle Jdeveloper 10G or version 9.0.5.2 , choose swing/Jclient for ADF under the client tier node and then choose Empty Form Wizard to build an application based on the business components From Table.
    i use JMenuBar to create MDI Form.
    this is Master Application: JClientForm.java
    =============
    package JClientTemp.view;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import oracle.jbo.RowIterator;
    import oracle.jbo.Row;
    import oracle.jbo.common.DefLocaleContext;
    import oracle.jbo.uicli.mom.JUMetaObjectManager;
    import oracle.jbo.uicli.binding.*;
    import oracle.jbo.uicli.controls.*;
    import oracle.jbo.uicli.*;
    import oracle.jbo.common.JBOClass;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import oracle.adf.model.*;
    import oracle.adf.model.binding.*;
    import oracle.adf.model.generic.*;
    import java.util.HashMap;
    import java.util.ArrayList;
    import oracle.jbo.uicli.jui.*;
    import javax.swing.JMenuBar;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.KeyStroke;
    import java.awt.event.KeyEvent;
    import java.awt.Event;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class JClientForm extends JFrame
    //public static TypeForm FormType(); // Syntax untuk Panggil form
    // form layout
    private GridLayout gridLayout = new GridLayout();
    private BorderLayout borderLayout = new BorderLayout();
    //private TypeForm FormType = new TypeForm();
    private TypeForm FormType; // Setting variable untuk call frame
    // panel definition used in design time
    private JUPanelBinding panelBinding = new JUPanelBinding("JClientFormUIModel");
    // Navigation bar
    // private JUNavigationBar navBar = new JUNavigationBar();
    // The status bar
    private JUStatusBar statusBar = new JUStatusBar();
    // The form's top panel
    private JPanel topPanel = new JPanel();
    private JPanel dataPanel = new JPanel();
    private JMenuBar menubarFrame = new JMenuBar();
    private JMenu menuFile = new JMenu();
    private JMenuItem itemFileCompList = new JMenuItem();
    private JMenuItem itemFileType = new JMenuItem();
    private JMenuItem itemFileInventory = new JMenuItem();
    private JMenuItem itemFileExit = new JMenuItem();
    //private JUNavigationBar hiddenNavBar = new JUNavigationBar();
    * the JbInit method
    public void jbInit() throws Exception
    // form layout
    dataPanel.setLayout(null);
    menuFile.setText("File");
    menuFile.setMnemonic('F');
    itemFileCompList.setText("Computer List");
    itemFileCompList.setMnemonic('C');
    itemFileType.setText("Type");
    itemFileType.setMnemonic('T');
    itemFileType.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, Event.ALT_MASK, false));
    itemFileType.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    itemFileType_actionPerformed(e);
    itemFileInventory.setText("Inventory");
    itemFileInventory.setMnemonic('I');
    itemFileExit.setText("Exit");
    itemFileExit.setMnemonic('X');
    itemFileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, Event.ALT_MASK, false));
    itemFileExit.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    item_file_exit_action(e);
    this.getContentPane().setLayout(gridLayout);
    this.setTitle("Master Form");
    this.setJMenuBar(menubarFrame);
    topPanel.setLayout(borderLayout);
    this.getContentPane().add(topPanel);
    this.setSize(new Dimension(400, 300));
    //topPanel.add(navBar, BorderLayout.NORTH);
    topPanel.add(dataPanel, BorderLayout.CENTER);
    topPanel.add(statusBar, BorderLayout.SOUTH);
    menuFile.add(itemFileCompList);
    menuFile.add(itemFileType);
    menuFile.add(itemFileInventory);
    menuFile.addSeparator();
    menuFile.add(itemFileExit);
    menubarFrame.add(menuFile);
    //hiddenNavBar.setModel(JUNavigationBar.createPanelBinding(panelBinding, hiddenNavBar));
    //navBar.setModel(JUNavigationBar.createPanelBinding(panelBinding, navBar));
    statusBar.setModel(JUStatusBar.createPanelBinding(panelBinding, statusBar));
    public static void main(String [] args)
    try
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch(Exception exemp)
    exemp.printStackTrace();
    try
    // bootstrap application
    JUMetaObjectManager.setBaseErrorHandler(new JUErrorHandlerDlg());
    JUMetaObjectManager mgr = JUMetaObjectManager.getJUMom();
    mgr.setJClientDefFactory(null);
    BindingContext ctx = new BindingContext();
    ctx.put(DataControlFactory.APP_PARAM_ENV_INFO, new JUEnvInfoProvider());
    ctx.setLocaleContext(new DefLocaleContext(null));
    HashMap map = new HashMap(4);
    map.put(DataControlFactory.APP_PARAMS_BINDING_CONTEXT, ctx);
    mgr.loadCpx("DataBindings.cpx", map);
    JClientForm frame = new JClientForm();
    frame.setBindingContext(ctx);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    // run this form
    if (frameSize.height > screenSize.height)
    frameSize.height = screenSize.height;
    if (frameSize.width > screenSize.width)
    frameSize.width = screenSize.width;
    frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    frame.setVisible(true);
    catch(Exception ex)
    JUMetaObjectManager.reportException(null, ex);
    System.exit(1);
    private int _popupTransactionDialog()
    if (panelBinding == null || panelBinding.getPanel() == null)
    return JOptionPane.NO_OPTION;
    if (panelBinding.isTransactionDirty())
    Object [] options = {"Commit", "Rollback"};
    int action = JOptionPane.showOptionDialog(JClientForm.this, "How do you want to close the transaction?", "Transaction open", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[(0)]);
    switch (action)
    case JOptionPane.NO_OPTION:
    hiddenNavBar.doAction(JUNavigationBar.BUTTON_ROLLBACK);
    break;
    case JOptionPane.CLOSED_OPTION:
    break;
    case JOptionPane.YES_OPTION:
    default:
    hiddenNavBar.doAction(JUNavigationBar.BUTTON_COMMIT);
    break;
    return action;
    return JOptionPane.NO_OPTION;
    public JUPanelBinding getPanelBinding()
    return panelBinding;
    public void setPanelBinding(JUPanelBinding binding)
    if (binding.getPanel() == null)
    binding.setPanel(topPanel);
    if (panelBinding == null || panelBinding.getPanel() == null)
    try
    panelBinding = binding;
    jbInit();
    catch(Exception ex)
    panelBinding.reportException(ex);
    * The default constructor for form
    public JClientForm()
    addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    //int action = _popupTransactionDialog();
    //if (action != JOptionPane.CLOSED_OPTION)
    panelBinding.releaseDataControl();
    setVisible(false);
    dispose();
    System.exit(0);
    public void setBindingContext(BindingContext bindCtx)
    if (panelBinding.getPanel() == null)
    panelBinding = panelBinding.setup(bindCtx, this);
    registerProjectGlobalVariables(bindCtx);
    panelBinding.refreshControl();
    try
    jbInit();
    panelBinding.refreshControl();
    catch(Exception ex)
    panelBinding.reportException(ex);
    private void registerProjectGlobalVariables(BindingContext bindCtx)
    JUUtil.registerNavigationBarInterface(panelBinding, bindCtx);
    private void unRegisterProjectGlobalVariables(BindingContext bindCtx)
    JUUtil.unRegisterNavigationBarInterface(panelBinding, bindCtx);
    private void item_file_exit_action(ActionEvent e)
    //int action = _popupTransactionDialog();
    //if (action != JOptionPane.CLOSED_OPTION)
    System.exit(0);
    private void itemFileType_actionPerformed(ActionEvent e)
    if (FormType==null)
    FormType.main2(null);
    else
    //FormType.setVisible(true);
    FormType.setVisible(true);
    ==========
    And Then that is Sub Application : TypeForm.java
    =================
    package JClientTemp.view;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Enumeration;
    import javax.swing.*;
    import javax.swing.event.*;
    import oracle.jbo.RowIterator;
    import oracle.jbo.Row;
    import oracle.jbo.common.DefLocaleContext;
    import oracle.jbo.uicli.mom.JUMetaObjectManager;
    import oracle.jbo.uicli.binding.*;
    import oracle.jbo.uicli.controls.*;
    import oracle.jbo.uicli.*;
    import oracle.jbo.common.JBOClass;
    import java.io.InputStream;
    import java.io.EOFException;
    import java.io.InputStreamReader;
    import oracle.adf.model.*;
    import oracle.adf.model.binding.*;
    import oracle.adf.model.generic.*;
    import java.util.HashMap;
    import java.util.ArrayList;
    import oracle.jbo.uicli.jui.*;
    import javax.swing.JTabbedPane;
    import java.awt.BorderLayout;
    import javax.swing.JPanel;
    import oracle.jbo.uicli.controls.JULabel;
    import java.awt.Rectangle;
    import oracle.jbo.uicli.jui.JULabelBinding;
    import javax.swing.JTextField;
    import javax.swing.text.Document;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.TableModel;
    import javax.swing.JButton;
    import javax.swing.ButtonModel;
    import java.awt.Font;
    import javax.swing.SwingConstants;
    import javax.swing.BorderFactory;
    import javax.swing.border.BevelBorder;
    import oracle.jbo.uicli.controls.JUNavigationBar;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.Component;
    public class java.io.EOFException extends java.io.IOException
    // Constructors
    public EOFException();
    public EOFException(String s);
    //import javax.swing.table.TableColumnModel;
    //import javax.swing.table.JTableHeader;
    //public static TypeForm FormType();
    public class TypeForm extends JFrame
    // form layout
    private GridLayout gridLayout = new GridLayout();
    private BorderLayout borderLayout = new BorderLayout();
    // panel definition used in design time
    private JUPanelBinding panelBinding = new JUPanelBinding("TypeFormUIModel");
    // Navigation bar
    // private JUNavigationBar navBar = new JUNavigationBar();
    // The status bar
    private JUStatusBar statusBar = new JUStatusBar();
    // The form's top panel
    private JPanel topPanel = new JPanel();
    //private JUNavigationBar hiddenNavBar = new JUNavigationBar();
    private JTabbedPane mainTab = new JTabbedPane();
    private JPanel tabTypeBC = new JPanel();
    private JPanel tabTypeSC = new JPanel();
    private JPanel tabTypeHC = new JPanel();
    private JULabel LblTypeBC = new JULabel();
    private JULabel LblDecTBC = new JULabel();
    private JTextField TxtTypeBC = new JTextField();
    private JTextField TxtDecTBC = new JTextField();
    private JScrollPane TBCScrollPane = new JScrollPane();
    private JTable TypeBCTable = new JTable();
    private JULabel LblTypeSC = new JULabel();
    private JULabel LblDecSC = new JULabel();
    private JTextField TxtTypeSC = new JTextField();
    private JTextField TxtDecTSC = new JTextField();
    private JScrollPane TSCScrollPane = new JScrollPane();
    private JTable TypeSCTable = new JTable();
    private JULabel LblTypeHC = new JULabel();
    private JULabel LblDecTHC = new JULabel();
    private JTextField TxtTypeHC = new JTextField();
    private JTextField TxtDecTHC = new JTextField();
    private JScrollPane THCScrollPane = new JScrollPane();
    private JTable TypeHCTable = new JTable();
    private JButton BtFirst = new JButton();
    private JButton BtPrev = new JButton();
    private JButton BtNext = new JButton();
    private JButton BtLast = new JButton();
    private JButton BtAdd = new JButton();
    private JButton BtDel = new JButton();
    private JButton BtSearch = new JButton();
    private JButton BtSubmit = new JButton();
    private JButton BtCommit = new JButton();
    private JButton BtRollback = new JButton();
    private JButton BFist = new JButton();
    private JButton BPrev = new JButton();
    private JButton BNext = new JButton();
    private JButton BLast = new JButton();
    private JButton BAdd = new JButton();
    private JButton BDelete = new JButton();
    private JButton BSearch = new JButton();
    private JButton BSubmit = new JButton();
    private JButton BCommit = new JButton();
    private JButton BRollBack = new JButton();
    private JButton BtClose = new JButton();
    private JButton BClose = new JButton();
    private JButton BhFirst = new JButton();
    private JButton BhPrev = new JButton();
    private JButton BhNext = new JButton();
    private JButton BhLast = new JButton();
    private JButton BhAdd = new JButton();
    private JButton BhDelete = new JButton();
    private JButton BhSearch = new JButton();
    private JButton BhSubmit = new JButton();
    private JButton BhCommit = new JButton();
    private JButton BhRollback = new JButton();
    private JButton BhClose = new JButton();
    //private TableColumnModel tableColumnModel1 = new javax.swing.table.DefaultTableColumnModel();
    * the JbInit method
    public void jbInit() throws Exception
    // form layout
    this.getContentPane().setLayout(gridLayout);
    this.setTitle("Form Type");
    topPanel.setLayout(borderLayout);
    tabTypeBC.setLayout(null);
    //tabTypeBC.setToolTipText("null");
    tabTypeSC.setLayout(null);
    tabTypeHC.setLayout(null);
    LblTypeBC.setText("jULabel1");
    LblTypeBC.setBounds(new Rectangle(15, 45, 115, 15));
    LblDecTBC.setText("jULabel1");
    LblDecTBC.setBounds(new Rectangle(15, 70, 115, 15));
    TxtTypeBC.setBounds(new Rectangle(135, 45, 85, 20));
    TxtDecTBC.setBounds(new Rectangle(135, 70, 185, 20));
    TBCScrollPane.setBounds(new Rectangle(15, 105, 305, 110));
    TypeBCTable.setEnabled(false);
    TypeBCTable.setEditingColumn(-1);
    TypeBCTable.setEditingRow(-1);
    LblTypeSC.setText("jULabel1");
    LblTypeSC.setBounds(new Rectangle(10, 50, 140, 15));
    LblDecSC.setText("jULabel1");
    LblDecSC.setBounds(new Rectangle(10, 75, 140, 15));
    TxtTypeSC.setBounds(new Rectangle(155, 50, 85, 20));
    TxtDecTSC.setBounds(new Rectangle(155, 75, 155, 20));
    TSCScrollPane.setBounds(new Rectangle(10, 110, 300, 105));
    TypeSCTable.setEnabled(false);
    TypeSCTable.setEditingColumn(-1);
    TypeSCTable.setEditingRow(-1);
    LblTypeHC.setText("jULabel1");
    LblTypeHC.setBounds(new Rectangle(10, 50, 140, 15));
    LblDecTHC.setText("jULabel1");
    LblDecTHC.setBounds(new Rectangle(10, 75, 140, 15));
    LblDecTHC.setToolTipText("null");
    TxtTypeHC.setBounds(new Rectangle(150, 45, 100, 20));
    TxtDecTHC.setBounds(new Rectangle(150, 75, 160, 20));
    THCScrollPane.setBounds(new Rectangle(10, 105, 300, 115));
    TypeHCTable.setEnabled(false);
    TypeHCTable.setEditingColumn(-1);
    TypeHCTable.setEditingRow(-1);
    BtFirst.setText("<<");
    BtFirst.setBounds(new Rectangle(15, 10, 20, 25));
    BtFirst.setFont(new Font("Dialog", 1, 8));
    BtFirst.setToolTipText("Move First Record");
    BtFirst.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtPrev.setText("<");
    BtPrev.setBounds(new Rectangle(35, 10, 20, 25));
    BtPrev.setFont(new Font("Dialog", 1, 8));
    BtPrev.setToolTipText("Move Previous Record");
    BtPrev.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtPrev.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    BtPrev_actionPerformed(e);
    BtNext.setText(">");
    BtNext.setBounds(new Rectangle(55, 10, 20, 25));
    BtNext.setFont(new Font("Dialog", 1, 8));
    BtNext.setToolTipText("Move Next Record");
    BtNext.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtLast.setText(">>");
    BtLast.setBounds(new Rectangle(75, 10, 20, 25));
    BtLast.setFont(new Font("Dialog", 1, 8));
    BtLast.setToolTipText("Move Last Record");
    BtLast.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtAdd.setText("Add");
    BtAdd.setBounds(new Rectangle(95, 10, 25, 25));
    BtAdd.setFont(new Font("Dialog", 1, 10));
    BtAdd.setToolTipText("Add Record");
    BtAdd.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtDel.setText("Del");
    BtDel.setBounds(new Rectangle(120, 10, 25, 25));
    BtDel.setFont(new Font("Dialog", 1, 10));
    BtDel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtDel.setToolTipText("Delete Record");
    BtSearch.setText("Search");
    BtSearch.setBounds(new Rectangle(145, 10, 40, 25));
    BtSearch.setFont(new Font("Dialog", 1, 10));
    BtSearch.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtSearch.setToolTipText("Search Record");
    BtSubmit.setText("Submit");
    BtSubmit.setBounds(new Rectangle(185, 10, 45, 25));
    BtSubmit.setFont(new Font("Dialog", 1, 10));
    BtSubmit.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtSubmit.setToolTipText("Submit Record");
    BtCommit.setText("Commit");
    BtCommit.setBounds(new Rectangle(230, 10, 45, 25));
    BtCommit.setFont(new Font("Dialog", 1, 10));
    BtCommit.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtCommit.setToolTipText("Commit Command");
    BtRollback.setText("Rollback");
    BtRollback.setBounds(new Rectangle(275, 10, 50, 25));
    BtRollback.setFont(new Font("Dialog", 1, 10));
    BtRollback.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtRollback.setToolTipText("RoolBack Command");
    BFist.setText("<<");
    BFist.setBounds(new Rectangle(10, 10, 20, 25));
    BFist.setFont(new Font("Dialog", 1, 8));
    BFist.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BFist.setToolTipText("Move First Record");
    BPrev.setText("<");
    BPrev.setBounds(new Rectangle(30, 10, 20, 25));
    BPrev.setFont(new Font("Dialog", 1, 8));
    BPrev.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BPrev.setToolTipText("Move Previous Record");
    BNext.setText(">");
    BNext.setBounds(new Rectangle(50, 10, 20, 25));
    BNext.setFont(new Font("Dialog", 1, 8));
    BNext.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BNext.setToolTipText("Move Next Record");
    BLast.setText(">>");
    BLast.setBounds(new Rectangle(70, 10, 20, 25));
    BLast.setFont(new Font("Dialog", 1, 8));
    BLast.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BLast.setToolTipText("Move Last Record");
    BAdd.setText("Add");
    BAdd.setBounds(new Rectangle(90, 10, 25, 25));
    BAdd.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BAdd.setFont(new Font("Dialog", 1, 10));
    BAdd.setToolTipText("Add Record");
    BDelete.setText("Del");
    BDelete.setBounds(new Rectangle(115, 10, 25, 25));
    BDelete.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BDelete.setFont(new Font("Dialog", 1, 10));
    BDelete.setToolTipText("Delete Record");
    BSearch.setText("Search");
    BSearch.setBounds(new Rectangle(140, 10, 40, 25));
    BSearch.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BSearch.setFont(new Font("Dialog", 1, 10));
    BSearch.setToolTipText("Search Record");
    BSubmit.setText("Submit");
    BSubmit.setBounds(new Rectangle(180, 10, 45, 25));
    BSubmit.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BSubmit.setFont(new Font("Dialog", 1, 10));
    BSubmit.setToolTipText("Submit Record");
    BCommit.setText("Commit");
    BCommit.setBounds(new Rectangle(225, 10, 45, 25));
    BCommit.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BCommit.setFont(new Font("Dialog", 1, 10));
    BCommit.setToolTipText("Commit Button");
    BRollBack.setText("Rollback");
    BRollBack.setBounds(new Rectangle(270, 10, 50, 25));
    BRollBack.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BRollBack.setFont(new Font("Dialog", 1, 10));
    BRollBack.setToolTipText("Rollback Button");
    BtClose.setText("Close");
    BtClose.setBounds(new Rectangle(325, 10, 35, 25));
    BtClose.setFont(new Font("Dialog", 1, 10));
    BtClose.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BtClose.setToolTipText("Close Sub Program");
    BtClose.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    BtClose_actionPerformed(e);
    BClose.setText("Close");
    BClose.setBounds(new Rectangle(320, 10, 35, 25));
    BClose.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BClose.setFont(new Font("Dialog", 1, 10));
    BClose.setToolTipText("Close Sub Program");
    BClose.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    BClose_actionPerformed(e);
    BhFirst.setText("<<");
    BhFirst.setBounds(new Rectangle(10, 10, 20, 25));
    BhFirst.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhFirst.setFont(new Font("Dialog", 1, 8));
    BhFirst.setToolTipText("Move First Record");
    BhPrev.setText("<");
    BhPrev.setBounds(new Rectangle(30, 10, 20, 25));
    BhPrev.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhPrev.setFont(new Font("Dialog", 1, 8));
    BhPrev.setToolTipText("Move Previous Record");
    BhNext.setText(">");
    BhNext.setBounds(new Rectangle(50, 10, 20, 25));
    BhNext.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhNext.setFont(new Font("Dialog", 1, 8));
    BhNext.setToolTipText("Move Next Record");
    BhLast.setText(">>");
    BhLast.setBounds(new Rectangle(70, 10, 20, 25));
    BhLast.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhLast.setFont(new Font("Dialog", 1, 8));
    BhLast.setToolTipText("Move Last Record");
    BhAdd.setText("Add");
    BhAdd.setBounds(new Rectangle(90, 10, 25, 25));
    BhAdd.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhAdd.setFont(new Font("Dialog", 1, 10));
    BhAdd.setToolTipText("Add Record");
    BhDelete.setText("Del");
    BhDelete.setBounds(new Rectangle(115, 10, 25, 25));
    BhDelete.setFont(new Font("Dialog", 1, 10));
    BhDelete.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhDelete.setToolTipText("Delete Record");
    BhSearch.setText("Search");
    BhSearch.setBounds(new Rectangle(140, 10, 40, 25));
    BhSearch.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhSearch.setFont(new Font("Dialog", 1, 10));
    BhSearch.setToolTipText("Search Record");
    BhSubmit.setText("Submit");
    BhSubmit.setBounds(new Rectangle(180, 10, 45, 25));
    BhSubmit.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhSubmit.setFont(new Font("Dialog", 1, 10));
    BhSubmit.setToolTipText("Submit Record");
    BhCommit.setText("Commit");
    BhCommit.setBounds(new Rectangle(225, 10, 45, 25));
    BhCommit.setToolTipText("Commit Record");
    BhCommit.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhCommit.setFont(new Font("Dialog", 1, 10));
    BhRollback.setText("Rollback");
    BhRollback.setBounds(new Rectangle(270, 10, 50, 25));
    BhRollback.setFont(new Font("Dialog", 1, 10));
    BhRollback.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhRollback.setToolTipText("Rollback Record");
    BhClose.setText("Close");
    BhClose.setBounds(new Rectangle(320, 10, 35, 25));
    BhClose.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    BhClose.setFont(new Font("Dialog", 1, 10));
    BhClose.setToolTipText("Close Sub Program");
    BhClose.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    BhClose_actionPerformed(e);
    this.getContentPane().add(topPanel);
    this.setSize(new Dimension(400, 300));
    //topPanel.add(navBar, BorderLayout.NORTH);
    topPanel.add(statusBar, BorderLayout.SOUTH);
    TBCScrollPane.getViewport().add(TypeBCTable, null);
    tabTypeBC.add(BtClose, null);
    tabTypeBC.add(BtRollback, null);
    tabTypeBC.add(BtCommit, null);
    tabTypeBC.add(BtSubmit, null);
    tabTypeBC.add(BtSearch, null);
    tabTypeBC.add(BtDel, null);
    tabTypeBC.add(BtAdd, null);
    tabTypeBC.add(BtLast, null);
    tabTypeBC.add(BtNext, null);
    tabTypeBC.add(BtPrev, null);
    tabTypeBC.add(BtFirst, null);
    tabTypeBC.add(TBCScrollPane, null);
    tabTypeBC.add(TxtDecTBC, null);
    tabTypeBC.add(TxtTypeBC, null);
    tabTypeBC.add(LblDecTBC, null);
    tabTypeBC.add(LblTypeBC, null);
    mainTab.addTab("Type Book", tabTypeBC);
    TSCScrollPane.getViewport().add(TypeSCTable, null);
    tabTypeSC.add(BClose, null);
    tabTypeSC.add(BRollBack, null);
    tabTypeSC.add(BCommit, null);
    tabTypeSC.add(BSubmit, null);
    tabTypeSC.add(BSearch, null);
    tabTypeSC.add(BDelete, null);
    tabTypeSC.add(BAdd, null);
    tabTypeSC.add(BLast, null);
    tabTypeSC.add(BNext, null);
    tabTypeSC.add(BPrev, null);
    tabTypeSC.add(BFist, null);
    tabTypeSC.add(TSCScrollPane, null);
    tabTypeSC.add(TxtDecTSC, null);
    tabTypeSC.add(TxtTypeSC, null);
    tabTypeSC.add(LblDecSC, null);
    tabTypeSC.add(LblTypeSC, null);
    mainTab.addTab("Type SoftWare", tabTypeSC);
    mainTab.addTab("Type Hardware", tabTypeHC);
    THCScrollPane.getViewport().add(TypeHCTable, null);
    tabTypeHC.add(BhClose, null);
    tabTypeHC.add(BhRollback, null);
    tabTypeHC.add(BhCommit, null);
    tabTypeHC.add(BhSubmit, null);
    tabTypeHC.add(BhSearch, null);
    tabTypeHC.add(BhDelete, null);
    tabTypeHC.add(BhAdd, null);
    tabTypeHC.add(BhLast, null);
    tabTypeHC.add(BhNext, null);
    tabTypeHC.add(BhPrev, null);
    tabTypeHC.add(BhFirst, null);
    tabTypeHC.add(THCScrollPane, null);
    tabTypeHC.add(TxtDecTHC, null);
    tabTypeHC.add(TxtTypeHC, null);
    tabTypeHC.add(LblDecTHC, null);
    tabTypeHC.add(LblTypeHC, null);
    topPanel.add(mainTab, BorderLayout.CENTER);
    //hiddenNavBar.setModel(JUNavigationBar.createPanelBinding(panelBinding, hiddenNavBar));
    //navBar.setModel(JUNavigationBar.createPanelBinding(panelBinding, navBar));
    statusBar.setModel(JUStatusBar.createPanelBinding(panelBinding, statusBar));
    LblTypeBC.setText("Type Book Code :");
    LblDecTBC.setText("Description :");
    TxtTypeBC.setDocument((Document)panelBinding.bindUIControl("TypeBc1", TxtTypeBC));
    TxtDecTBC.setDocument((Document)panelBinding.bindUIControl("Description1", TxtDecTBC));
    TypeBCTable.setModel((TableModel)panelBinding.bindUIControl("TypeBookView1", TypeBCTable));
    LblTypeSC.setText("Type Software Code :");
    LblDecSC.setText("Description :");
    TxtTypeSC.setDocument((Document)panelBinding.bindUIControl("TypeSc1", TxtTypeSC));
    TxtDecTSC.setDocument((Document)panelBinding.bindUIControl("Description3", TxtDecTSC));
    TypeSCTable.setModel((TableModel)panelBinding.bindUIControl("TypeSoftwareView1", TypeSCTable));
    LblTypeHC.setText("Type Hardware Code :");
    LblDecTHC.setText("Description :");
    TxtTypeHC.setDocument((Document)panelBinding.bindUIControl("TypeHc1", TxtTypeHC));
    TxtDecTHC.setDocument((Document)panelBinding.bindUIControl("Description5", TxtDecTHC));
    TypeHCTable.setModel((TableModel)panelBinding.bindUIControl("TypeHardwareView1", TypeHCTable));
    BtFirst.setModel((ButtonModel)panelBinding.bindUIControl("First", BtFirst));
    BtFirst.setText("<<");
    BtPrev.setModel((ButtonModel)panelBinding.bindUIControl("Previous", BtPrev));
    BtPrev.setText("<");
    BtNext.setModel((ButtonModel)panelBinding.bindUIControl("Next", BtNext));
    BtNext.setText(">");
    BtLast.setModel((ButtonModel)panelBinding.bindUIControl("Last", BtLast));
    BtLast.setText(">>");
    BtAdd.setModel((ButtonModel)panelBinding.bindUIControl("Create", BtAdd));
    BtAdd.setText("Add");
    BtDel.setModel((ButtonModel)panelBinding.bindUIControl("Delete", BtDel));
    BtDel.setText("Del");
    BtSearch.setModel((ButtonModel)panelBinding.bindUIControl("Find", BtSearch));
    BtSearch.setText("Search");
    BtSubmit.setModel((ButtonModel)panelBinding.bindUIControl("Execute", BtSubmit));
    BtSubmit.setText("Submit");
    BtCommit.setModel((ButtonModel)panelBinding.bindUIControl("Commit", BtCommit));
    BtCommit.setText("Commit");
    BtRollback.setModel((ButtonModel)panelBinding.bindUIControl("Rollback", BtRollback));
    BtRollback.setText("Rollback");
    BFist.setModel((ButtonModel)panelBinding.bindUIControl("First1", BFist));
    BFist.setText("<<");
    BPrev.setModel((ButtonModel)panelBinding.bindUIControl("Previous1", BPrev));
    BPrev.setText("<");
    BNext.setModel((ButtonModel)panelBinding.bindUIControl("Next1", BNext));

  • CTRL + V and CTRL + C

    How do I lock the keys CTRL + C and CTRL + V in a TextField?
    Thanks
    Edited by: 892672 on 10/11/2011 02:19

    You need to use EventFilter in TextField to avoid the user to Copy and Paste.
    txt.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>(){
         public void handle(KeyEvent event) {
              if(event.isControlDown()){
                   if(event.getCode() == KeyCode.C || event.getCode() == KeyCode.V){
                        event.consume();
    });Thanks.
    Narayan

  • Switching Look and Feel

    menu = new JMenu ( "Look and Feel" );
    menu.setMnemonic ( KeyEvent.VK_L );
    menuBar.add ( menu );
    JMenuItem lookAndFeel[];
    final UIManager.LookAndFeelInfo laf[] = UIManager.getInstalledLookAndFeels();
    lookAndFeel = new JMenuItem[laf.length];
    for ( int i = 0; i < laf.length; i++ )
    lookAndFeel[i] = new JMenuItem ( laf.getName() );
                   lookAndFeel[i].addActionListener (
                        new ActionListener() {
                             public void actionPerformed ( ActionEvent e )
                                  UIManager.setLookAndFeel ( laf[i].getClassName() );
                                  SwingUtilities.updateComponentTreeUI ();
                   menu.add ( lookAndFeel[i] );

    i get these errors, can someone give me a hand at the solution?
    C:\app\Applicatie.java:198: local variable i is accessed from within inner class; needs to be declared final
                                  UIManager.setLookAndFeel ( laf.getClassName() );
    ^
    C:\app\Applicatie.java:199: updateComponentTreeUI(java.awt.Component) in javax.swing.SwingUtilities cannot be applied to ()
                                  SwingUtilities.updateComponentTreeUI ();
    Many thanks

  • 8820: Symbol EventInjector$KeyEvent. init not found

    Hi
     I am creating a custom application for blackberry which uses the EventInjector API and more precisely the following code:
     EventInjector.KeyEvent inject = new EventInjector.KeyEvent(EventInjector.KeyEvent.KEY_DOWN,Characters.ESCAPE,50);inject.post(); inject.post();
    The code works on the Bold and on all the devices I tried through the simulator but does not work for the 8820.
    The error I get is when I try to start the application and is:
    Symbol EventInjector$KeyEvent.<init> not found
    I am not sure what I am missing, permissions are wide open for the Application itself. Any Ideas?
    Any help would be appreciated.
    Thx
    xtos

    please refer infoDoc#89603, recompile the program will resolve the issue, then could you please send your app sample code to me ([email protected]) so that I can made the doc more perfect.

  • Accessibilty and JPopupMenu

    I am using JAWS 6 with JDK 1.4.2_06 and Access Bridge 1.2.
    If I add Menuitems to a JMenu which is added to the menubar everything works as expected. One of the menu items is another JMenu, a sub-menu. When JAWS reads this it speaks "submenu" indicating that there is a sub-menu to the right of the current menu item. However, If I attached the exact same menuitems to a JPopupMenu,
    JAWS never speaks "submenu" so the user has no iindication that there is a sub-menu to the right.
    I've taken the attached code from "The JFC Swing Tutorial - Second Edition" and tweaked it slightly so the menubar and popup menu contain the same items.
    It seems as if the accessibility api is expecting the first set of menu items to be attached to a menu parent.
    If worked around this for now by adding another top level menu to the popupmenu to which I add the menuitems.
    Is this a Java or JAWS bug ?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    * Like MenuDemo, but with popup menus added.
    public class TextFieldDemo {
    JTextArea output;
    JScrollPane scrollPane;
    String newline = "\n";
    public JMenuBar createMenuBar() {
    JMenuBar menuBar;
    JMenu menu;
    //Create the menu bar.
    menuBar = new JMenuBar();
    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription(
    "The only menu in this program that has menu items");
    JMenuItem[] mi = createAMenu();
    for(int i=0; i < mi.length; ++i)
    menu.add(mi);
    menuBar.add(menu);
    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription(
    "This menu does nothing");
    menuBar.add(menu);
    return menuBar;
    public Container createContentPane() {
    //Create the content-pane-to-be.
    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setOpaque(true);
    //Create a scrolled text area.
    output = new JTextArea(5, 30);
    output.setEditable(false);
    scrollPane = new JScrollPane(output);
    //Add the text area to the content pane.
    contentPane.add(scrollPane, BorderLayout.CENTER);
    return contentPane;
    public void createPopupMenu() {
    JMenuItem menuItem;
    //Create the popup menu.
    JPopupMenu popup = new JPopupMenu();
    JMenuItem[] mi = createAMenu();
    for(int i=0; i < mi.length; ++i)
    popup.add(mi[i]);
    //Add listener to the text area so the popup menu can come up.
    MouseListener popupListener = new PopupListener(popup);
    output.addMouseListener(popupListener);
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("TextFieldDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create/set menu bar and content pane.
    TextFieldDemo demo = new TextFieldDemo();
    frame.setJMenuBar(demo.createMenuBar());
    frame.setContentPane(demo.createContentPane());
    //Create and set up the popup menu.
    demo.createPopupMenu();
    //Display the window.
    frame.setSize(450, 260);
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    class PopupListener extends MouseAdapter {
    JPopupMenu popup;
    PopupListener(JPopupMenu popupMenu) {
    popup = popupMenu;
    public void mousePressed(MouseEvent e) {
    maybeShowPopup(e);
    public void mouseReleased(MouseEvent e) {
    maybeShowPopup(e);
    private void maybeShowPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
    popup.show(e.getComponent(),
    e.getX(), e.getY());
    private JMenuItem[] createAMenu()
    JMenu submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;
    JMenuItem items[] = new JMenuItem[8];
    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item",
    KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription(
    "This doesn't really do anything");
    items[0]=menuItem;
    menuItem = new JMenuItem("Both text and icon");
    menuItem.setMnemonic(KeyEvent.VK_B);
    items[1]=menuItem;
    menuItem = new JMenuItem("icon only");
    menuItem.setMnemonic(KeyEvent.VK_D);
    items[2]=menuItem;
    //a group of radio button menu items
    ButtonGroup group = new ButtonGroup();
    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    items[3]=rbMenuItem;
    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    items[4]=rbMenuItem;
    //a group of check box menu items
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    items[5]=cbMenuItem;
    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    items[6]=cbMenuItem;
    //a submenu
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);
    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_2, ActionEvent.ALT_MASK));
    submenu.add(menuItem);
    menuItem = new JMenuItem("Another item");
    submenu.add(menuItem);
    items[7]=submenu;
    return(items);

    Hi;
    I want to add chekboxes to a poupup menu ,how can I do that. I already have a submenu with names of columns ton hide and show them using chekcboxes and i want that same menu as a popup when i click in the tableheader.
    thanx

  • Trying to scroll a JComponent with JScrollPane but can't do it. :(

    Hi, what im trying to do seems to be simple but I gave up after trying the whole day and I beg you guys help.
    I created a JComponent that is my map ( the map consists only in squared cells ). but the map might be too big for the screen, so I want to be able to scroll it. If the map is smaller than the screen,
    everything works perfect, i just add the map to the frame container and it shows perfect. But if I add the map to the ScrollPane and them add the ScrollPane to the container, it doesnt work.
    below is the code for both classes Map and the MainWindow. Thanks in advance
    package main;
    import java.awt.Color;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowStateListener;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JViewport;
    public class MainWindow implements WindowStateListener {
         private JFrame frame;
         private static MainWindow instance = null;
         private MenuBar menu;
         public Map map = new Map();
         public JScrollPane Scroller =
              new JScrollPane( map,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
         public JViewport viewport = new JViewport();
         private MainWindow(int width, int height) {
              frame = new JFrame("Editor de Cen�rios v1.0");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(width,height);
              frame.setVisible(true);
              menu = MenuBar.createMenuBar();
              JFrame.setDefaultLookAndFeelDecorated(false);
              frame.setJMenuBar(menu.create());
              frame.setBackground(Color.WHITE);
              frame.getContentPane().setBackground(Color.WHITE);
                                    // HERE IS THE PROBLEM, THIS DOESNT WORKS   <---------------------------------------------------------------------------------------
              frame.getContentPane().add(Scroller);
              frame.addWindowStateListener(this);
    public static MainWindow createMainWindow(int width, int height)
         if(instance == null)
              instance = new MainWindow(width,height);
              return instance;               
         else
              return instance;
    public static MainWindow returnMainWindow()
         return instance;
    public static void main(String[] args) {
         MainWindow mWindow = createMainWindow(800,600);
    public JFrame getFrame() {
         return frame;
    public Map getMap(){
         return map;
    @Override
    public void windowStateChanged(WindowEvent arg0) {
         map.repaint();
    package main;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import javax.swing.JComponent;
    import javax.swing.Scrollable;
    public class Map extends JComponent  implements Scrollable{
         private Cell [] mapCells;
         private String mapPixels;
         private String mapAltura;
         private String mapLargura;
         public void createMap(String pixels , String altura, String largura)
              mapPixels = pixels;
              mapAltura = altura;
              mapLargura = largura;
              int cells = Integer.parseInt(altura) * Integer.parseInt(largura);
              mapCells = new Cell[cells];
              //MainWindow.returnMainWindow().getFrame().getContentPane().add(this);
              Graphics2D grafico = (Graphics2D)getGraphics();
              for(int i=0, horiz = 0 , vert = 0; i < mapCells.length; i++)
                   mapCells[i] = new Cell( horiz, vert,Integer.parseInt(mapPixels));
                   MainWindow.returnMainWindow().getFrame().getContentPane().add(mapCells);
                   grafico.draw(mapCells[i].r);
                   horiz = horiz + Integer.parseInt(mapPixels);
                   if(horiz == Integer.parseInt(mapLargura)*Integer.parseInt(mapPixels))
                        horiz = 0;
                        vert = vert + Integer.parseInt(mapPixels);
              repaint();
         @Override
         protected void paintComponent(Graphics g) {
              super.paintComponent(g);
              System.out.println("entrou");
              Graphics2D g2d = (Graphics2D)g;
              if(mapCells !=null)
                   for(int i=0, horiz = 0 , vert = 0; i < mapCells.length; i++)
                        g2d.draw(mapCells[i].r);
                        horiz = horiz + Integer.parseInt(mapPixels);
                        if(horiz == Integer.parseInt(mapLargura)*Integer.parseInt(mapPixels))
                             horiz = 0;
                             vert = vert + Integer.parseInt(mapPixels);
         @Override
         public Dimension getPreferredScrollableViewportSize() {
              return super.getPreferredSize();
         @Override
         public int getScrollableBlockIncrement(Rectangle visibleRect,
                   int orientation, int direction) {
              // TODO Auto-generated method stub
              return 5;
         @Override
         public boolean getScrollableTracksViewportHeight() {
              // TODO Auto-generated method stub
              return false;
         @Override
         public boolean getScrollableTracksViewportWidth() {
              // TODO Auto-generated method stub
              return false;
         @Override
         public int getScrollableUnitIncrement(Rectangle visibleRect,
                   int orientation, int direction) {
              // TODO Auto-generated method stub
              return 5;

    Im so sorry Darryl here are the other 3 classes
    package main;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.filechooser.FileNameExtensionFilter;
    public class MenuActions {
         public void newMap(){
              final JTextField pixels = new JTextField(10);
              final JTextField hCells = new JTextField(10);
              final JTextField wCells = new JTextField(10);
              JButton btnOk = new JButton("OK");
              final JFrame frame = new JFrame("Escolher dimens�es do mapa");
              frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(),BoxLayout.Y_AXIS));
              btnOk.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
              String txtPixels = pixels.getText();
              String hTxtCells = hCells.getText();
              String wTxtCells = wCells.getText();
              frame.dispose();
              MainWindow.returnMainWindow().map.createMap(txtPixels,hTxtCells,wTxtCells);         
              frame.getContentPane().add(new JLabel("N�mero de pixels em cada c�lula:"));
              frame.getContentPane().add(pixels);
              frame.getContentPane().add(new JLabel("Altura do mapa (em c�lulas):"));
              frame.getContentPane().add(hCells);
              frame.getContentPane().add(new JLabel("Largura do mapa (em c�lulas):"));
              frame.getContentPane().add(wCells);
              frame.getContentPane().add(btnOk);
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setSize(300, 165);
              frame.setResizable(false);
             frame.setVisible(true);
         public Map openMap (){
              //Abre somente arquivos XML
              JFileChooser fc = new JFileChooser();
              FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml" );
              fc.addChoosableFileFilter(filter);
              fc.showOpenDialog(MainWindow.returnMainWindow().getFrame());
              //TO DO: manipular o mapa aberto
              return new Map();          
         public void save(){
         public void saveAs(){
              //Abre somente arquivos XML
              JFileChooser fc = new JFileChooser();
              FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml" );
              fc.addChoosableFileFilter(filter);
              fc.showSaveDialog(MainWindow.returnMainWindow().getFrame());
              //TO DO: Salvar o mapa aberto
         public void exit(){
              System.exit(0);          
         public void copy(){
         public void paste(){
    package main;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.KeyStroke;
    public class MenuBar implements ActionListener{
         private JMenuBar menuBar;
         private final Color color = new Color(250,255,245);
         private String []menuNames = {"Arquivo","Editar"};
         private JMenu []menus = new JMenu[menuNames.length];
         private String []arquivoMenuItemNames = {"Novo","Abrir", "Salvar","Salvar Como...","Sair" };
         private KeyStroke []arquivoMenuItemHotkeys = {KeyStroke.getKeyStroke(KeyEvent.VK_N,ActionEvent.CTRL_MASK),
                                                                  KeyStroke.getKeyStroke(KeyEvent.VK_A,ActionEvent.CTRL_MASK),
                                                                  KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK),
                                                                  KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.SHIFT_MASK),
                                                                  KeyStroke.getKeyStroke(KeyEvent.VK_F4,ActionEvent.ALT_MASK)};
         private JMenuItem []arquivoMenuItens = new JMenuItem[arquivoMenuItemNames.length];
         private String []editarMenuItemNames = {"Copiar","Colar"};
         private KeyStroke []editarMenuItemHotKeys = {KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK),
                                                                 KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK)};
         private JMenuItem[]editarMenuItens = new JMenuItem[editarMenuItemNames.length];
         private static MenuBar instance = null;
         public JMenuItem lastAction;
         private MenuBar()
         public static MenuBar createMenuBar()
              if(instance == null)
                   instance = new MenuBar();
                   return instance;                    
              else
                   return instance;
         public JMenuBar create()
              //cria a barra de menu
              menuBar = new JMenuBar();
              //adiciona items a barra de menu
              for(int i=0; i < menuNames.length ; i++)
                   menus[i] = new JMenu(menuNames);
                   menuBar.add(menus[i]);
              //seta a hotkey da barra como F10
              menus[0].setMnemonic(KeyEvent.VK_F10);
              //adiciona items ao menu arquivo
              for(int i=0; i < arquivoMenuItemNames.length ; i++)
                   arquivoMenuItens[i] = new JMenuItem(arquivoMenuItemNames[i]);
                   arquivoMenuItens[i].setAccelerator(arquivoMenuItemHotkeys[i]);
                   menus[0].add(arquivoMenuItens[i]);
                   arquivoMenuItens[i].setBackground(color);
                   arquivoMenuItens[i].addActionListener(this);
              //adiciona items ao menu editar
              for(int i=0; i < editarMenuItemNames.length ; i++)
                   editarMenuItens[i] = new JMenuItem(editarMenuItemNames[i]);
                   editarMenuItens[i].setAccelerator(editarMenuItemHotKeys[i]);
                   menus[1].add(editarMenuItens[i]);
                   editarMenuItens[i].setBackground(color);
                   editarMenuItens[i].addActionListener(this);
              menuBar.setBackground(color);
              return menuBar;                    
         @Override
         public void actionPerformed(ActionEvent e) {
              lastAction = (JMenuItem) e.getSource();
              MenuActions action = new MenuActions();
              if(lastAction.getText().equals("Novo"))
                   action.newMap();
              else if(lastAction.getText().equals("Abrir"))
                   action.openMap();
              else if(lastAction.getText().equals("Salvar"))
                   action.save();               
              else if(lastAction.getText().equals("Salvar Como..."))
                   action.saveAs();               
              else if(lastAction.getText().equals("Sair"))
                   action.exit();               
              else if(lastAction.getText().equals("Copiar"))
                   action.copy();               
              else if(lastAction.getText().equals("Colar"))
                   action.paste();               
    package main;
    import java.awt.geom.Rectangle2D;
    import javax.swing.JComponent;
    public class Cell extends JComponent{
         public float presSub = 0;
         public double errPressInfer = 0.02;
         public double errPressSup = 0.02;
         public float profundidade = 1;
         public Rectangle2D r ;
         public Cell(double x, double y, double pixel)
              r = new Rectangle2D.Double(x,y,pixel,pixel);          
    Edited by: xnunes on May 3, 2008 6:26 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Newbie : Using "this" in a function

    I have a function in my main class that spawns
    a Dialog for user input. The strange thing is, that I get
    a compiler error anytime i try to use "this" inside my
    function. Please help. Can you see anything wrong
    with the code in this function? I am calling it from
    another class.
    public static void createNewCell() {
    JDialog newDialog = new JDialog();
    newDialog.setTitle("New Cell Site");
    newDialog.setResizable(false);
    newDialog.setModal(true);
    //create txt fields
    CDBTextField txtCellID = new CDBTextField(15,10);
    //create buttons
    JButton btnOK = new JButton("OK");
    btnOK.setActionCommand("ok");
    btnOK.addActionListener(this);
    JButton btnCancel = new JButton("Cancel");
    btnCancel.setActionCommand("cancel");
    btnCancel.addActionListener(this);
    //Layout the labels in a panel
    JPanel labelPane = new JPanel();
    labelPane.setLayout(new GridLayout(0, 1));
    labelPane.add(new JLabel("Cell ID:"));
    //Layout the text fields in a panel
    JPanel fieldPane = new JPanel();
    fieldPane.setLayout(new GridLayout(0, 1));
    fieldPane.add(txtCellID);
    //Layout the buttons in a panel
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new GridLayout(0, 2));
    buttonPane.add(btnCancel);
    buttonPane.add(btnOK);
    //Put the panels in another panel, labels on left,
    //text fields on right
    JPanel contentPane = new JPanel();
    contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    contentPane.setLayout(new BorderLayout(10,10));
    contentPane.add(labelPane, BorderLayout.CENTER);
    contentPane.add(fieldPane, BorderLayout.EAST);
    contentPane.add(buttonPane, BorderLayout.SOUTH);
    newDialog.setContentPane(contentPane);
    newDialog.pack();
    newDialog.show();
    Here is the compiler message
    CDBTest.java:152: non-static variable this cannot be referenced from a static co
    ntext
    btnOK.addActionListener(this);
    ^
    CDBTest.java:155: non-static variable this cannot be referenced from a static co
    ntext
    btnCancel.addActionListener(this);
    ^
    2 errors
    I guess I don't really understand how to use static and
    when not to use static, and how to use "this"
    But I know I need to use "this" for the actionlisteners
    on my buttons.
    THanks
    Josh

    Thank you , Thank you, Thank you!
    Here is my entire main class, and then below it I'll
    paste the class that is calling my function.
    import java.io.*;
    import java.util.StringTokenizer;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.ArrayList;
    public class CDBTest extends JFrame implements ActionListener {
            public static CellList cellList = new CellList();
            public static Tabs cdbTabs = new Tabs();
            public static ArrayList cellArrayList = new ArrayList();
            public static int internalCellId = 0;    
            public CDBTest() {
                    JMenuBar mainMenuBar = new JMenuBar();
                    JMenu mainMenu;
                    JMenuItem mainMenuItem;
                    JPanel mainPanel = new JPanel();
                    //Attach Menu Bar
                    setJMenuBar(mainMenuBar);
                    //Build the first menu.
                    mainMenu = new JMenu("File");
                    mainMenu.setMnemonic(KeyEvent.VK_F);
                    mainMenuBar.add(mainMenu);
                    //JMenuItems
                    mainMenuItem = new JMenuItem("New",KeyEvent.VK_N);
                    mainMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
                    mainMenuItem.addActionListener(this);
                    mainMenu.add(mainMenuItem);
                    mainMenuItem = new JMenuItem("Open",KeyEvent.VK_O);
                    mainMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
                    mainMenuItem.addActionListener(this);
                    mainMenu.add(mainMenuItem);
                    mainMenu.addSeparator();
                    mainMenuItem = new JMenuItem("Save",KeyEvent.VK_S);
                    mainMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
                    mainMenuItem.addActionListener(this);
                    mainMenu.add(mainMenuItem);
                    mainMenuItem = new JMenuItem("Save As",KeyEvent.VK_A);
                    mainMenuItem.addActionListener(this);
                    mainMenu.add(mainMenuItem);
                    mainMenu.addSeparator();
                    mainMenuItem = new JMenuItem("Exit",KeyEvent.VK_E);
                    mainMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
                    mainMenuItem.addActionListener(this);
                    mainMenu.add(mainMenuItem);
                    //define main content panel
                    mainPanel.setPreferredSize(new Dimension(600, 350));
                    //Turn border off for now 3/19/02
                    //mainPanel.setBorder(BorderFactory.createLineBorder(Color.black));
                    setResizable(false);
                    setTitle("Cell Site Database Editor");
                    //define and add components
                    mainPanel.add(cellList);
                    mainPanel.add(cdbTabs);
                    setContentPane(mainPanel);
            public void actionPerformed(ActionEvent e) {
                    JMenuItem source = (JMenuItem)(e.getSource());
                    if (source.getText() == "Open") {
                            // "." represents current dir, NOT APP-DIR,
                            // AND worse, the "Up" feature in filechooser now broken
                            // DAMNIT!
                            //final JFileChooser fc = new JFileChooser(".");
                            final JFileChooser fc = new JFileChooser();
                            fc.addChoosableFileFilter(new CDBFileFilter());
                            int returnVal = fc.showOpenDialog(this);
                            if (returnVal == JFileChooser.APPROVE_OPTION) {
                                    File file = fc.getSelectedFile();
                                    //this is where a real application would open the file.
                                    //JOptionPane.showMessageDialog(this, "Opening " + file.getName());
                                    try {
                                            // Clear out any existing entries
                                            if (cellList.isFilled()) {
                                                    cellArrayList.clear();
                                                    cellList.removeAllFromJList();
                                                    internalCellId = 0;
                                            FileReader cdbReader = new FileReader(file);
                                            BufferedReader br = new BufferedReader(cdbReader);
                                            //JComboBox cellList = new JComboBox();
                                            //cellList.addActionListener(this);
                                            String line;
                                            while((line = br.readLine()) != null){
                                                    // Looping through each line
                                                    cellArrayList.add(internalCellId, Split(line,",")); //Add array with an index
                                                    String[] arCells = (String[]) cellArrayList.get(internalCellId); //Extract array object and cast as a String Array
                                                    cellList.AddCell(arCells[0] + " " + arCells[1]);
                                                    //cellList.addItem(arCells[0] + " " + arCells[1]);
                                                    internalCellId++;
                                            cellList.list.setSelectedIndex(0);
                                    } catch (FileNotFoundException fnf) {
                                            System.err.println("Unable to open file for reading: " + fnf.getMessage());
                                    } catch (IOException ioe) {
                                            System.err.println("unable to buffer read file: " + ioe.getMessage());
                            } else {
                                    JOptionPane.showMessageDialog(this, "Cancelled ");
                    } else if (source.getText() == "Exit") {
                            System.exit(0);
                    } else {
                            String s = "Action event detected.\n"
                               + "    Event source: " + source.getText()
                               + " (an instance of " + getClassName(source) + ")";
                            JOptionPane.showMessageDialog(this, s);
            public static String[ ] Split(String str2Split, String separator) {
                    StringTokenizer parser = new StringTokenizer(str2Split, separator);
                    int numTokens=parser.countTokens( );
                    String[ ] arString = new String[numTokens];
                    for (int i=0; i < numTokens; i++) {
                            arString[i] = parser.nextToken( );
                    return arString;
            public void createNewCell() {
                    JDialog newDialog = new JDialog();
                    newDialog.setTitle("New Cell Site");
                    newDialog.setResizable(false);
                    newDialog.setModal(true);
                    //create txt fields
                    CDBTextField txtCellID = new CDBTextField(15,10);
                    CDBTextField txtCellName = new CDBTextField(15,20);
                    CDBTextField txtSwitch = new CDBTextField(15,10);
                    CDBTextField txtSectorID = new CDBTextField(1,1);
                    CDBTextField txtSectorName = new CDBTextField(15,12);
                    //create buttons
                    JButton btnOK = new JButton("OK");
                    btnOK.setActionCommand("ok");
                    btnOK.addActionListener(this);
                    JButton btnCancel = new JButton("Cancel");
                    btnCancel.setActionCommand("cancel");
                    btnCancel.addActionListener(this);
                    //Layout the labels in a panel
                    JPanel labelPane = new JPanel();
                    labelPane.setLayout(new GridLayout(0, 1));
                    labelPane.add(new JLabel("Cell ID:"));
                    labelPane.add(new JLabel("Cell Name:"));
                    labelPane.add(new JLabel("Switch:"));
                    labelPane.add(new JLabel("Sector ID:"));
                    labelPane.add(new JLabel("Sector Name:"));
                    //Layout the text fields in a panel
                    JPanel fieldPane = new JPanel();
                    fieldPane.setLayout(new GridLayout(0, 1));
                    fieldPane.add(txtCellID);
                    fieldPane.add(txtCellName);
                    fieldPane.add(txtSwitch);
                    fieldPane.add(txtSectorID);
                    fieldPane.add(txtSectorName);
                    //Layout the buttons in a panel
                    JPanel buttonPane = new JPanel();
                    buttonPane.setLayout(new GridLayout(0, 2));
                    buttonPane.add(btnCancel);
                    buttonPane.add(btnOK);
                    //Put the panels in another panel, labels on left,
                    //text fields on right
                    JPanel contentPane = new JPanel();
                    contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
                    contentPane.setLayout(new BorderLayout(10,10));
                    contentPane.add(labelPane, BorderLayout.CENTER);
                    contentPane.add(fieldPane, BorderLayout.EAST);
                    contentPane.add(buttonPane, BorderLayout.SOUTH);
                    newDialog.setContentPane(contentPane);
                    newDialog.pack();
                    newDialog.show();      
            // Returns just the class name -- no package info.
            protected String getClassName(Object o) {
                    String classString = o.getClass().getName();
                    int dotIndex = classString.lastIndexOf(".");
                    return classString.substring(dotIndex+1);
            public static void main(String args[]) {
                    final CDBTest CDBApp = new CDBTest();
                    CDBApp.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                            System.exit(0);
                    CDBApp.pack();
                    CDBApp.show();
    I'm new to Java and trying tio pick it up as I code
    so please give me any recommendations you have
    some things I don't really understand.
    And here is the code of my class that calls the function
    in my main class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ActionButtons extends JPanel implements ActionListener {
            protected JButton btnNew, btnCopy, btnDelete;
            private int btnWidth = 35;
            private int btnHeight = 34;
            public ActionButtons() {
                    ImageIcon icoBtnNew = new ImageIcon("images/new.gif");
                    ImageIcon icoBtnCopy = new ImageIcon("images/copy.gif");
                    ImageIcon icoBtnDelete = new ImageIcon("images/delete.gif");
                    btnNew = new JButton(icoBtnNew);
                    btnNew.setPreferredSize(new Dimension(btnWidth,btnHeight));
                    btnNew.setToolTipText("Create a new cell site.");
                    btnNew.setActionCommand("new");
                    btnNew.addActionListener(this);
                    add(btnNew);
                    btnCopy = new JButton(icoBtnCopy);
                    btnCopy.setPreferredSize(new Dimension(btnWidth,btnHeight));
                    btnCopy.setToolTipText("Copy selected cell site.");
                    btnCopy.setActionCommand("copy");
                    btnCopy.addActionListener(this);
                    add(btnCopy);
                    btnDelete = new JButton(icoBtnDelete);
                    btnDelete.setPreferredSize(new Dimension(btnWidth,btnHeight));
                    btnDelete.setToolTipText("Delete selected cell site.");
                    btnDelete.setActionCommand("delete");
                    btnDelete.addActionListener(this);
                    add(btnDelete);
           public void actionPerformed(ActionEvent e) {
                    if (e.getActionCommand() == "new") {
                            //switch tabs to general tab
                            CDBTest.createNewCell();
    Thanks
    Josh

  • Input map of components / overriding native key commands

    Hi, I am in the process of developing a game engine on the Java language and have basically hit a brick wall =D
    As my application runs through a java.awt.Frame, I need to be able to disable all native commands of key-to-event mapping. For instance, when I press the Alt key, then press down, I don't want a little pop-up menu to display in the upper-left corner. Another example is that I don't want Alt-F4 to always close the window, etc.
    I have played around with listeners, but listeners to nothing but allow me to do something more than the key was previously assigned to; they don't prevent anything.
    So, any ideas? I have handled the problem in the past by overwriting actions in a JComponent's InputMap/ActionMap. But, as Components do not implement InputMap or ActionMap, I'm stuck like a rock in a hard place =D
    (Swing is not as efficient for rendering as AWT is, so I can't migrate to a Swing-based GUI)
    If anybody has any suggestions, please let me know =D
    Thanks in advance
    Alex

    try this for your alt-F4
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class Testing extends JFrame
      boolean isAltF4 = false;
      public Testing()
        setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel p = new JPanel(new GridLayout(2,1));
        p.add(new JTextField(10));
        p.add(new JButton("OK"));
        getContentPane().add(p);
        pack();
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
          .addKeyEventDispatcher(new KeyEventDispatcher(){
            public boolean dispatchKeyEvent(KeyEvent ke){
              if(ke.getID()==KeyEvent.KEY_PRESSED && ke.getKeyCode() == KeyEvent.VK_F4 && ke.isAltDown())
                isAltF4 = true;
                ke.consume();
              if(ke.getID()==KeyEvent.KEY_TYPED && isAltF4) ke.consume();
              if(ke.getID()==KeyEvent.KEY_RELEASED) isAltF4 = false;
            return false;}});
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • Problem with Mnemonic Alt F4 with JWindow in solaris OS urgent!......

    hi all
    I have a problem with JWindow i created a menu where in i have all menuitems as i needed with a close MenuItem with Mnemonic ALT F4 i could not able to close the JWindow in solaris as iam not able to catch th e ALT F4 event please help guys and gals.

    HI JRG
    look my code once when i run this code iam not able to catch ALT F4 press as when iam printing the key pressed iam not able to catch ALT F4 any suggestions please
    import javax.swing.*;
    import java.awt.event.*;
    public class MyWindow extends JWindow implements KeyListener, WindowListener
    public MyWindow(){
    super();
    addKeyListener( this);// for closing
    addWindowListener( this);// for focus
    show();
    // implement the window listener
    public void windowClosing( WindowEvent e ) {
    //System.exit(0);
    public void windowClosed( WindowEvent e ) {}
    public void windowActivated( WindowEvent e ) {}
    public void windowDeactivated( WindowEvent e ) {}
    public void windowDeiconified( WindowEvent e ) {}
    public void windowIconified( WindowEvent e ) {}
    public void windowOpened( WindowEvent e ){
    requestFocus();
    // implement the key listener
    public void keyReleased( KeyEvent e){}
    public void keyTyped( KeyEvent e){}
    public void keyPressed( KeyEvent e){
    if( (e.getKeyCode() == KeyEvent.VK_F4) && (e.getModifiers() == InputEvent.ALT_MASK)){
    e.consume();
    dispose();
    System.exit( 0);
    public static void main(String s[])
    MyWindow mywin=new MyWindow();
    mywin.setSize(400,400);

  • Help!About HotKeys

    I need help!!
    Now, i want to make an application with several hotKeys in JFrame.My source like this:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import java.util.*;
    public class Demo extends JFrame {
    public Demo () {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    private void jbInit() throws Exception {
    this.enableEvents(AWTEvent.KEY_EVENT_MASK);
    getContentPane().setLayout(null);
    closeBtt.setBounds(new Rectangle(0, 13, 19, 40));
    closeBtt.setBorder(new TitledBorder(""));
    closeBtt.setHorizontalAlignment(SwingConstants.LEFT);
    closeBtt.setHorizontalTextPosition(SwingConstants.LEFT);
    closeBtt.setMargin(new Insets(0, 0, 0, 0));
    closeBtt.setMnemonic('0');
    closeBtt.setText("X");
    closeBtt.setVerticalAlignment(SwingConstants.TOP);
    closeBtt.setVerticalTextPosition(SwingConstants.TOP);
    this.setEnabled(true);
    templateLab.setText("template");
    templateLab.setBounds(new Rectangle(23, 25, 80, 17));
    templateCB.setBounds(new Rectangle(103, 23, 109, 21));
    codeLab.setText("name");
    codeLab.setBounds(new Rectangle(225, 26, 33, 17));
    codeTxt.setBounds(new Rectangle(266, 23, 63, 21));
    setBtt.setBounds(new Rectangle(340, 20, 79, 27));
    setBtt.setBorder(new TitledBorder(""));
    setBtt.setText("set");
    getContentPane().add(templateCB, null);
    getContentPane().add(codeTxt, null);
    getContentPane().add(setBtt, null);
    getContentPane().add(closeBtt, null);
    getContentPane().add(templateLab, null);
    this.getContentPane().add(codeLab, null);
    protected void processKeyEvent(KeyEvent evt) {
    super.processKeyEvent(evt);
    if(evt.getKeyCode() == KeyEvent.VK_F4){
    System.out.println("AAAA");
    public static void main(String[] args) {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch(Exception e) {
    Demo demo = new Demo();
    demo.setBounds(50,50,479, 80);
    demo.show();
    private JButton closeBtt = new JButton();
    private JLabel templateLab = new JLabel();
    private JComboBox templateCB = new JComboBox();
    private JLabel codeLab = new JLabel();
    private JTextField codeTxt = new JTextField();
    private JButton setBtt = new JButton();
    when i clicked the F4 button, i can not catch the KeyEvent. "AAAA" is not printed.
    What problem with my program?
    help me, plz
    thank u
    BTW, if i remove all the components from JFrame except label, "AAAA" will be printed.
    i used JDK1.4.0,JDK1.4.01 and JDK1.4.1beta, all are no response, but jdk1.3.1 can run my demo.
    Now, i must use jdk1.4.0 or more higher version.how can i resolve it?

    Personally I'd recommend throwing away JBuilder's UI builder for a start - these things usually they generate appalling code!
    The code you've got seems to use the AWT inheritance event model that was abandoned around JDK1.1, being replaced by the delegation model.
    Anyway, I'd advise doing this by registering a keyboard action with your JFrame:
    ActionListener hotKeyAction = new ActionListener()
      public void actionPerformed(ActionEvent e)
        System.out.println("AAAA");
    getRootPane().registerKeyboardAction(hotKeyAction, KeyStroke.getKeyStroke("F4"), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);Hope this helps.

  • Imitating 2 keyboard buttons at the same time like ALT+F4

    hello,
    was just wonderin how to Imitatate 2 keyboard buttons at the same time like ALT+F4. i am using the Robot class to make the key board pressing and they are working fo one button. i tried two buttons like this
    robot.keyPress(KeyEvent.ALT_MASK+KeyEvent.VK_F4);but no luck. anyone know how to do this
    thanks
    martin

    martinnaughton wrote:
    sorry was just trying to do CTRL button but it does not like this bit of code.
    robot.keyPress(KeyEvent.CTRL_DOWN_MASK);
                        robot.keyPress(KeyEvent.VK_UP);gives me an exception of invalid code.It does not seem to like DOWN_MASK attributes in java.
    any way else around it
    thanks
    martinDon't confuse the modifier bitmask codes with the key codes:
    robot.keyPress(KeyEvent.VK_CONTROL);

  • Handling event problem

    Hi boys and girls.
    I've been working in a multiframe GUI. I have a main window (a custom class extending JFrame) with a menu.
    My menu items events are beeing handled by my custom class that implements ActionListener. This cutom class, through actionPerformed(ActionEvent e) method, handles all my button events and the menu items events. To manage focus i also implemented in this class the WindowListener interface, listening to all other frames of my application, so that they can behave more or less like a modal JDialog does.
    One of my menu items is a 'Quit' option. It simply exits the application if there is no changed data on a JList or asks the user if he wants to save changes first. As i said before this action is handled by actionPerformed(ActionEvent e) in my custom class.
    Once the WindowListener interface is already implemented i thought i could make the frame respond the same way when the user clicks the 'X' icon just by implementing on the windowClosing(WindowEvent we) method a redirection to actionPerformed li ke this:
    public void windowClosing(WindowEvent e){
              this.dispacthEvent(new ActionEvent(quitItem, ActionEvent.ACTION_PERFORMED, quitItem.getActionCommand()));
    being quitItem my JMenuItem. My interpretation is that, before exiting the system, it would first launch the code that i've established within actionPerformed for the quit option.
    Am i completely wrong or am i doing at least something correctly?
    Please help me. Thank you

    Instead of that do this:
            mainWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); //This is handled by windowClosing.
            mainWindow.addWindowListener(new QuitListener());
            menuItem = new JMenuItem("Quit", KeyEvent.VK_Q);
            menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
            menuItem.getAccessibleContext().setAccessibleDescription("Exit the program");
            menuItem.addActionListener(new QuitListener());
            menu.add(menuItem);
    class QuitListener implements ActionListener, WindowListener{
            public void actionPerformed(ActionEvent event) {
                    checkForSaveAndClose(); //Or System.exit(0) if you don't want to do something on close.
            public void windowClosing(WindowEvent e) {
                    checkForSaveAndClose();
            public void windowClosed(WindowEvent e) { }
            public void windowOpened(WindowEvent e) { }
            public void windowIconified(WindowEvent e) { }
            public void windowDeiconified(WindowEvent e) { }
            public void windowActivated(WindowEvent e) { }
            public void windowDeactivated(WindowEvent e) { }
            public void windowGainedFocus(WindowEvent e) { }
            public void windowLostFocus(WindowEvent e) { }
            public void windowStateChanged(WindowEvent e) { }
    }Or, at least, that's what I'm doing. As I understand it this is the more correct way. Feel free to correct me if I'm wrong.

Maybe you are looking for

  • IPhoto won't open! How can I get it to open?

    (Hey, I just checked in after not doing so for many months........ and I like this new letter template!!) I have Snow Leopard 10.6.8. (It says 10.6.5 below, but that has not yet been updated.) The message window says that I have iPhoto 9.1.5 installe

  • 2 Final Questions

    Sorry for all the threads asking questions, im almost set on a Mac Mini. 1. Are there any good torrent clients, such as Bitlord, Bitcomet. And will .torrent files work on Mac, as long as I have a Mac Torrent Client? 2. If I get the wireless keyboard

  • Creating visual representations of data

    Hello World! This is my first Java project and I'm a little bit scared. I'm hoping someone can give me a general pointer or advice on how to approach the structure and setup of this project. I want to create a Java tool that will allow a user to inpu

  • Method CL_FAGL_OI_READ giving dump

    Hi,      method giving dump when i m trying to use it. st 22 stmt. In program "CL_FAGL_OI_READ===============CP ", the following syntax error   occurred                                                                    in the Include "CL_FAGL_OI_REA

  • Can't get wi fi to work on  my computer; does on another

    Back at home and the ipad2 won't work on my newer computer. However, it was trying to connect previously but wanted a password?? Which I had not idea, what it was. Just received this ipad2 yesterday. Works fine at another location on an older compute