JMenu (on JPanel)

I have an application that needs a menu but I can't have it at the top where a normal JMenu should go, what can I do? I have used JMenus on JFrames before but was wondering/hoping there was a simliar way to use a JMenu directly on a JPanel of some sort (?).

Add the JMenubar with its JMenus to the JPanel just like a normal component, but make sure you change the layout manager of the JMenubar to says GridLayout (or BoxLayout with Y_AXIS layout), so that it can appear vertical instead of the default horizontal produced by its default BoxLayout with X_AXIS layout
ICE

Similar Messages

  • Event handling in JMenu in JPanel

    Hi,
    I'm writing a small register program GUI. I have a problem with ActionListener in JMenu. I wrote a JPanel which creates a JMenu and that works just fine. The problem is that id doesn't give any event signals. I have another class which impelemets ActionListener and it works fine with JButton (another panel for buttons), but not with JMenu.
    Below is the JPanel for JMenu and Application which implements the ActionListener. Do you see anything wrong? I really can't imagine why I cannot get the action signals. JPanel is defined in JFrame as it should be. Have you got any ideas?
    Regards,
    Marko
    class MenuPanel extends JPanel {
         protected JMenuBar menuBar;
         protected JMenu menu;
         protected JMenuItem loadRegister;
         protected JMenuItem saveRegister;
         protected JMenuItem information;
         protected JMenuItem quit;
         public MenuPanel(Application application) {
              menuBar = new JMenuBar();          
              menu = new JMenu("Tiedosto");     
              loadRegister = new JMenuItem("Lataa");
              loadRegister.addActionListener(application);
              saveRegister = new JMenuItem("Talleta");
              saveRegister.addActionListener(application);
              information = new JMenuItem("Tietoja");
              information.addActionListener(application);
              quit = new JMenuItem("Lopeta");                    quit.addActionListener(application);
              menu.add(loadRegister);
              menu.add(saveRegister);
              menu.addSeparator();
              menu.add(information);
              menu.add(quit);          
              menuBar.add(menu);
    class Application implements ActionListener {     
         // Define CardPanel
         private CardPanel cardPanel;
         // Define linked list for cards
         private CardList cardList = null;
         // Constructor. Initializes cardPanel and cardList
         public Application(CardPanel cardPanelRefrence) {
              cardPanel = cardPanelRefrence;
              cardList = new CardList();
         public void actionPerformed(ActionEvent action) {
              String actionPerformed = action.getActionCommand();
              if (actionPerformed.equals("Lataa")) {
                   load();          
              if (actionPerformed.equals("Talleta")) {
                   save();          
              if (actionPerformed.equals("Tietoja")) {
                   info();          
              if (actionPerformed.equals("Lopeta")) {
                   System.exit(0);
    // Continues with the methods...

    Well, I found the answer. Heh, quite easy one but it took a while before I found it..
    Just if you ever have similar problem. The problem was that in my JFrame I didn't create an object of class (Application) which implement s the ActionListener before using it as a reference in creating JPanel object. Quite confusing explanation, but here the code. This code was in my JFrame which was not included in this question.
    private Application application;
    private MenuPanel menuPanel;
    application = new Application(cardPanel, rightInfoPanel);
    menuPanel = new MenuPanel(application);
    These two were introduced other way round, so that variable "application" was null. What a problem in fact.. :)
    - Marko

  • JMenu is behind Canvas. problem ?

    I have created a JFrame with a JMenuBar,
    I have added a ImageCanvas (sub class of Canvas) in the center of the JFrame
    but whenever i click on Menu it appears behind the canvas
    what to do pls help?

    Hey,
    Canvas is an awt component meaning it is a heavyweight
    component. The swing components are lightweight.
    Thats the problem.
    Have a look at the following URL.
    http://java.sun.com/products/jfc/tsc/articles/mixing/
    It should explain about mixing heavyweight/lightweight
    components
    Basically you either need to use Frame, Menu and
    canvas or JFrame, JMenu and JPanel.
    nesAnd heres the important part:
    "When a lightweight component overlaps a heavyweight component, the heavyweight component is always on top,
    regardless of the relative z-order of the two components."
    Use JPanel instead of canvas if your using swing.
    regards,
    Tim

  • Clear content pane problems

    can anyone tell why can't I clear the content pane in the following code or a method to achieve this thing?
    thank you.
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package librabrymanagementf;
    import java.awt.event.ActionEvent;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import javax.swing.SwingUtilities;
    import java.io.*;
    import java.io.File;
    import java.lang.Object;
    * @author emi
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) {
                  // Creates a model of the system logic.
            libraryModel model = new libraryModel();
            // Creaties a view for the system logic.
            libraryView view = new libraryView();
            // Creates a controller that links the two.
            libraryController controller = new libraryController(model, view);
      class libraryModel{
       public void addToFile(String title, String author, String ID){
       try{   
        FileWriter fw= new FileWriter("file.txt",true);
        fw.write(title+"\t"+author+"\t"+ID);
        fw.write("\r\n");
        fw.close();}
        catch (IOException e)
                   System.err.println ("Unable to write to file");
                   System.exit(-1);
      class libraryView{
          libraryModel model= new libraryModel();
         JFrame frame = new JFrame("[=] JMenuBar [=]");
        JMenuItem addBook = new JMenuItem("Add Book");
        JMenuItem deleteBook = new JMenuItem("Delete Book");
        JMenu modifyBook = new JMenu("Modify Book");
        JMenuItem modifyByTitle = new JMenuItem("Modify by Title");
        JMenuItem modifyByAuthor = new JMenuItem("Modify by Author");
        JMenu searchBook = new JMenu("Search Book");
        JMenuItem searchByTitle = new JMenuItem("Search by Title");
        JMenuItem searchByAuthor = new JMenuItem("Search by Author");
        JMenuItem searchByID = new JMenuItem("Search by ID");
        JMenuItem bookListing = new JMenuItem("Book Listing");
        JMenuBar menuBar = new JMenuBar();
        JMenu menu = new JMenu("Options");
        JPanel panel;
        JPanel textPanel, panelForTextFields, completionPanel;
        JLabel titleLabel, authorLabel, IDLabel, bookTitleLabel, passLabel;
        JTextField bookTitleField, authorField, IDField;
        JButton loginButton;
    public libraryView(){
         createAndShowGUI();
    public void CreateMenuBar()
          menuBar.add(menu);
          menu.add(addBook);
          menu.add(deleteBook);
          modifyBook.add(modifyByTitle);
          modifyBook.add(modifyByAuthor);
          menu.add(modifyBook);
          searchBook.add(searchByTitle);
          searchBook.add(searchByAuthor);
          searchBook.add(searchByID);
          menu.add(searchBook);
          menu.add(bookListing);
          frame.setJMenuBar(menuBar);
       public void createAndShowGUI(){
          frame.setSize(400,400);
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          CreateMenuBar();
       public void addBookForm(){
            JPanel panel = new JPanel();
            clear(panel);
            panel.setLayout(null);
            titleLabel = new JLabel("Add Book");
            titleLabel.setLocation(0,0);
            titleLabel.setSize(290, 30);
            titleLabel.setHorizontalAlignment(0);
            panel.add(titleLabel);
            // Creation of a Panel to contain the JLabels
            textPanel = new JPanel();
            textPanel.setLayout(null);
            textPanel.setLocation(10, 35);
            textPanel.setSize(70, 150);
            panel.add(textPanel);
            // Book title Label
            bookTitleLabel = new JLabel("Title");
            bookTitleLabel.setLocation(0, 0);
            bookTitleLabel.setSize(70, 40);
            bookTitleLabel.setHorizontalAlignment(4);
            textPanel.add(bookTitleLabel);
          // Book author Label
            authorLabel = new JLabel("Author");
            authorLabel.setLocation(0, 40);
            authorLabel.setSize(70, 40);
            authorLabel.setHorizontalAlignment(4);
            textPanel.add(authorLabel);
             // Book ID Label
            IDLabel = new JLabel("ID");
            IDLabel.setLocation(0, 80);
            IDLabel.setSize(70, 40);
            IDLabel.setHorizontalAlignment(4);
            textPanel.add(IDLabel);
             // TextFields Panel Container
            panelForTextFields = new JPanel();
            panelForTextFields.setLayout(null);
            panelForTextFields.setLocation(110, 47);
            panelForTextFields.setSize(200, 130);
            panel.add(panelForTextFields);
            // book title Textfield
            bookTitleField = new JTextField(8);
            bookTitleField.setLocation(0, 0);
            bookTitleField.setSize(200, 20);
            panelForTextFields.add(bookTitleField);
            // book author Textfield
            authorField = new JTextField(8);
            authorField.setLocation(0, 40);
            authorField.setSize(200, 20);
            panelForTextFields.add(authorField);
            //book id Textfield
            IDField = new JTextField(8);
            IDField.setLocation(0, 80);
            IDField.setSize(200,20);
            panelForTextFields.add(IDField);
             // Button for Submit
            loginButton = new JButton("Submit");
            loginButton.setLocation(170, 180);
            loginButton.setSize(80, 20);
            loginButton.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
                     String bookTitle = bookTitleField.getText().trim();
                     String bookAuthor = authorField.getText().trim();
                     String bookID = IDField.getText().trim();
                     int intBookID = Integer.parseInt(bookID);
                     model.addToFile(bookTitle, bookAuthor, bookID);
            panel.add(loginButton);
            panel.setOpaque(true);   
            frame.getContentPane().add(panel, BorderLayout.CENTER);
            frame.setVisible(true);
              clear(panel);
       public void deleteBookForm(){
            JPanel panel = new JPanel();
            panel.setLayout(null);
            titleLabel = new JLabel("Delete Book");
            titleLabel.setLocation(0,0);
            titleLabel.setSize(290, 30);
            titleLabel.setHorizontalAlignment(0);
            panel.add(titleLabel);
             panel.setOpaque(true);   
             frame.getContentPane().add(panel, BorderLayout.CENTER);
            frame.setVisible(true);
        clear(panel);
       public void clear(JPanel panel){
           panel.removeAll();
           panel.validate();
        public void MenuActionListeners(ActionListener al) {
            addBook.setActionCommand("addBook");
            addBook.addActionListener(al);
            deleteBook.setActionCommand("deleteBook");
            deleteBook.addActionListener(al);
            modifyByTitle.setActionCommand("modifyByTitle");
            modifyByTitle.addActionListener(al);
            modifyByAuthor.setActionCommand("modifyByAuthor");
            modifyByAuthor.addActionListener(al);
            searchByTitle.setActionCommand("searchByTitle");
            searchByTitle.addActionListener(al);
            searchByAuthor.setActionCommand("searchByAuthor");
            searchByAuthor.addActionListener(al);
            searchByID.setActionCommand("searchByID");
            searchByID.addActionListener(al);
            bookListing.setActionCommand("bookListing");
            bookListing.addActionListener(al);
    class libraryController implements ActionListener{
         libraryModel model;
         libraryView view;
       public libraryController (libraryModel model, libraryView view) {
            this.model = model;
            this.view  = view;
          //  this.view.init_view();
            view.MenuActionListeners(this);
         //   view.addBookListeners(this);
       public void actionPerformed(ActionEvent ae)
        String action_com = ae.getActionCommand();
            if (action_com.equals("addBook")){
            // view.clear();
             view.addBookForm();
            else if (action_com.equals("deleteBook")){
          //  view.clear();
            view.deleteBookForm();
            System.out.println("kk");
            else if (action_com.equals("modifyByTitle")){
                 System.out.println(action_com);
            else if (action_com.equals("modifyByAuthor")){
                 System.out.println(action_com);
            else if (action_com.equals("searchByTitle")){
                 System.out.println(action_com);
            else if (action_com.equals("searchByAuthor")){
                 System.out.println(action_com);
            else if (action_com.equals("searchByID")){
                 System.out.println(action_com);
            else if (action_com.equals("bookListing")){
                 System.out.println(action_com);
        Thanks!

    Please pare down your code to a manageable amount. You don't need 3/4 of that code to demonstrate your problem, so why should you ask us to read it??

  • Adding JMenu directly to a JPanel

    I am trying to add a JMenu directly to a JPanel, but it isn't functioning properly. It shows up, and looks the way I expect (with an arrow, like a sub-menu), but it doesn't display its popup menu when clicked. If I add the menu to a JMenuBar, and add that to the panel, it works, but the popup drops down below the button instead of to the right, and the arrow disappears. JMenuBar appears to be adding its own actions to every menu that it contains. JMenu is a descendant of AbstractButton, so I figured it would behave like one, but no luck.
    Any help would be appreciated. By the way, I have thought of using a JButton and a JPopupMenu together, but that is not a very elegant solution. I am looking for a way to make the JMenu behave as if it were in a JMenuBar.

    Hello Vijesh
    See the code below and tell me whether it is useful ?
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class SwingA implements ActionListener
    JPopupMenu pop;
    JFrame frame;
    JPanel panel;
    JButton cmdPop;
         public static void main(String[] args)
         SwingA A=new SwingA();
         SwingA()
                   frame=new JFrame("PopUp");
                   frame.setSize(600,480);
                   frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                   pop=new JPopupMenu();
                   cmdPop=new JButton("Click");
                   cmdPop.addActionListener(this);
    JMenuItem item = new JMenuItem("First");
    JMenuItem item1 = new JMenuItem("Second");
    pop.add(item);
    pop.add(item1);
                   panel=new JPanel();
                   panel.add(cmdPop);
                   frame.getContentPane().add(panel);
                   frame.setVisible(true);
         public void actionPerformed(ActionEvent source)
    pop.show(cmdPop, cmdPop.getWidth(), 0);
    kanad

  • JMenu hidden unde JPanel

    Hi,
    I write same simple application, and I have problem with a JMenu. When I make simple JMenu, and add it to this application, menu this will be hiden under JPanel and other controls...
    Here id code:
    Hi,
    I write same simple application, and I have problem with a JMenu. When I make simple JMenu, and add it to this application, menu this will be hiden under JPanel and other controls...
    Here id code:
    package pl.staniszczak.JFakturka.GUI;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.GridLayout;
    import java.awt.Panel;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFormattedTextField;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JScrollPane;
    import javax.swing.JSpinner;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import pl.staniszczak.JFakturka.GUI.Actions.DrukujFaktureAction;
    import pl.staniszczak.JFakturka.GUI.Models.TowaryATModel;
    * @author Administrator
    public class MainFrame extends JFrame {
         private JTextField jtfNrFaktury;
         private JFormattedTextField jftfDataSprzedazy;
         private JFormattedTextField jftfDataFaktury;
         private JComboBox jcbPlatnosc;
         private JSpinner jsTerminPlatnosci;
         private JTextField jtfUwagi;
         private JTable jtTowary;
         private JButton jbDodajTowar;
         private JButton jbUsunTowar;
         public MainFrame() {
              setTitle("JFakturka 1.0");
              setResizable(false);
              setSize(450,400);
           * Menus
            JMenu menuFaktura = new JMenu("Faktura");
            JMenuItem drukuj = menuFaktura.add(new DrukujFaktureAction("Drukuj"));
            JMenuBar menuBar = new JMenuBar();
            setJMenuBar(menuBar);
            menuBar.add(menuFaktura);
             * Układ komponent�w
              //gł�wny layout
              GridLayout gridLayout = new GridLayout(2,1);
              getContentPane().setLayout(gridLayout);
              //layout na kompionenty tekstowe
              Panel pnlText = new Panel();
              GridBagLayout gblLayout = new GridBagLayout();
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.anchor = GridBagConstraints.WEST;
              pnlText.setLayout(gblLayout);
              add(pnlText);
            * Komponenty
              //Numer faktury
            JLabel jlblNrFaktury = new JLabel("Numer Faktury");
            buildConstraints(constraints, 0,0,1,1,100,100);
            gblLayout.setConstraints(jlblNrFaktury, constraints);
            pnlText.add(jlblNrFaktury);
            jtfNrFaktury = new JTextField(25);
            buildConstraints(constraints, 1,0,3,1,100,100);
            gblLayout.setConstraints(jtfNrFaktury, constraints);
            pnlText.add(jtfNrFaktury);
            //Data sprzedaży
            JLabel jlblDataSprzedazy = new JLabel("Data sprzedaży");
            buildConstraints(constraints, 0,2,1,1,100,100);
            gblLayout.setConstraints(jlblDataSprzedazy, constraints);
            pnlText.add(jlblDataSprzedazy);
            jftfDataSprzedazy = new JFormattedTextField();
            buildConstraints(constraints, 1,2,1,1,100,100);
            gblLayout.setConstraints(jftfDataSprzedazy, constraints);
            pnlText.add(jftfDataSprzedazy);
            //Data faktury
            JLabel jlblDataFaktury = new JLabel("Data faktury");
            buildConstraints(constraints, 2,2,1,1,100,100);
            gblLayout.setConstraints(jlblDataFaktury, constraints);
            pnlText.add(jlblDataFaktury);
            jftfDataFaktury = new JFormattedTextField();
            buildConstraints(constraints, 3,2,1,1,100,100);
            gblLayout.setConstraints(jftfDataFaktury, constraints);
            pnlText.add(jftfDataFaktury);
            //Płatność
            JLabel jlblPlatnosc = new JLabel("Płatność");
            buildConstraints(constraints, 0,3,1,1,100,100);
            gblLayout.setConstraints(jlblPlatnosc, constraints);
            pnlText.add(jlblPlatnosc);
            jcbPlatnosc = new JComboBox(new String[]{"Got�wka", "Przelew", "Inna"});
            buildConstraints(constraints, 1,3,1,1,100,100);
            gblLayout.setConstraints(jcbPlatnosc, constraints);
            pnlText.add(jcbPlatnosc);
            //Termin płatności
            JLabel jlblTerminPlatnosc = new JLabel("Termin");
            buildConstraints(constraints, 2,3,1,1,100,100);
            gblLayout.setConstraints(jlblTerminPlatnosc, constraints);
            pnlText.add(jlblTerminPlatnosc);
            jsTerminPlatnosci = new JSpinner();
            buildConstraints(constraints, 3,3,1,1,100,100);
            gblLayout.setConstraints(jsTerminPlatnosci, constraints);
            pnlText.add(jsTerminPlatnosci);
            //Uwagi
            JLabel jlblUwagi = new JLabel("Uwagi");
            buildConstraints(constraints, 0,4,1,1,100,100);
            gblLayout.setConstraints(jlblUwagi, constraints);
            pnlText.add(jlblUwagi);
            jtfUwagi = new JTextField(25);
            buildConstraints(constraints, 1,4,3,1,100,100);
            gblLayout.setConstraints(jtfUwagi, constraints);
            pnlText.add(jtfUwagi);
            //Dodaj towar
              jbDodajTowar = new JButton("Dodaj towar");
            buildConstraints(constraints, 0,5,4,1,100,100);
            gblLayout.setConstraints(jbDodajTowar, constraints);
            pnlText.add(jbDodajTowar);
            //Usuń towar
              jbUsunTowar = new JButton("Usun towar");
            buildConstraints(constraints, 1,5,4,1,100,100);
            gblLayout.setConstraints(jbUsunTowar, constraints);
            pnlText.add(jbUsunTowar);
            //Towary
            TowaryATModel towaryModel = new TowaryATModel();
            jtTowary = new JTable(towaryModel);
            add(new JScrollPane(jtTowary));
         public void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) {
              gbc.gridx = gx;
              gbc.gridy = gy;
              gbc.gridwidth = gw;
              gbc.gridheight = gh;
              gbc.weightx = wx;
              gbc.weighty = wy;
    }

    It's my bug - I use Panel from AWT. When I replace it by JPanel, it's start work:-)

  • I want to have JMenu on a Side bar(JPanel) with sub menu.

    I want to have the JMenu on the sidebar(which is a
    JPanel placed at WEST). This JMenu shall have the sub
    menu with it. I got the JMenu on the Sidebar but when
    i take mouse over(or click) the MenuItem it is
    displaying the sub Menu. I am attaching the my code.
    Can anyone please let me know why it is not displaying
    the sub menu and what should be added to my code to
    work?
    Thanks in Advance(see below for code)
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class SideBarMenu extends JFrame {
         JMenuItem menuItem1,menuItem2;
         JMenu books, softwares, tools;
         JSeparator horizontal1, horizontal2,horizontal3;
         JPanel p1, p2;
          public static void main(String[] args) {
           SideBarMenu vAR =  new SideBarMenu();
         public SideBarMenu() {
              super("Side Bar");
              setSize(500,500);
              setLocation(150,100);
              setResizable(true);     
              Container content = getContentPane();
              p1 = new JPanel(new BorderLayout());
              p2 = new JPanel();
              p2.setLayout(new GridLayout(20,1));
              p2.setBorder(BorderFactory.createLineBorder(Color.black,1));
              books = new JMenu("Books");
              horizontal1 = new JSeparator( JSeparator.HORIZONTAL );
              softwares = new JMenu("Softwares");
              horizontal2 = new JSeparator( JSeparator.HORIZONTAL );
              tools = new JMenu("Tools");
                                    horizontal3 = new JSeparator( JSeparator.HORIZONTAL );
              //sub Menu for menu "books"     
              menuItem1 = new JMenuItem("Java");
              books.add(menuItem1);
              menuItem2 = new JMenuItem(".Net");
              books.add(menuItem2);
              //sub Menu for menu "Softwares"          
              menuItem1 = new JMenuItem("Java");
              softwares.add(menuItem1);
              menuItem2 = new JMenuItem(".Net");
              softwares.add(menuItem2);
              //sub Menu for menu "tools"          
              menuItem1 = new JMenuItem("Java");
              tools.add(menuItem1);
              menuItem2 = new JMenuItem(".Net");
              tools.add(menuItem2);
              p2.add(books);
              p2.add(horizontal1);
              p2.add(softwares);
              p2.add(horizontal2);
              p2.add(tools);
              p2.add(horizontal3);
              p1.add(p2,BorderLayout.WEST );
              content.add(p1);
              setVisible(true);
    }

    Hi Ashwin,
    I saw the above code which is approaching my requirement... Thats cool man. Taking that as reference i modified it to make it what i want. The code i have modified and which is very closer to my requirement is attached below. I have set the Windows Look and Feel, because its easy to track my problems with it. The problems am having are:
    1) When the mouse is removed from the menu its submenu is not disappearing.
    2) When i take the mouse over the menu its making the name(Books/softwares/tools) of the menu invisible.
    3) When i take the mouse over the sub menu items they are not getting highlighted, which means they are not listening
    I hope u will solve these issues for me...
    Also make the menu items work ie., just make them print when i click submenus like "Clicked books->java" and "clicked softwares->.Net" so that i get an idea of events....
    Many Thanks .
    Here we go,
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.GridLayout;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JPopupMenu;
    import javax.swing.JSeparator;
    import javax.swing.UIManager;
    public class SideBarMenu4 extends JFrame
        JMenuBar menuBar;
        JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem1, menuItem2;
        JMenu books, softwares, tools;
        JLabel mainMenu = new JLabel("Main Menu");
        JMenu subMenu;
        JSeparator horizontal1, horizontal2, horizontal3;
        JPanel p1, p2;
        public static void main(String[] args)
            SideBarMenu4 vAR = new SideBarMenu4();
        public SideBarMenu4()
            super("Side Bar");
            setSize(500, 500);
            setLocation(150, 100);
            setResizable(true);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            Container content = getContentPane();
            p1 = new JPanel(new BorderLayout());
                        try {
              //MetalLookAndFeel.setCurrentTheme(new MacMetricsTheme());
                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");            
            } catch(Exception e) {}
            p2 = new JPanel();
            p2.setLayout(new GridLayout(30, 1));
            p2.setBorder(BorderFactory.createLineBorder(Color.black, 1));
            books = new JMenu("Books");
            horizontal1 = new JSeparator(JSeparator.HORIZONTAL);
            softwares = new JMenu("Softwares");
            horizontal2 = new JSeparator(JSeparator.HORIZONTAL);
            tools = new JMenu("Tools");
            horizontal3 = new JSeparator(JSeparator.HORIZONTAL);
            // sub Menu for menu "books"
            menuItem1 = new JMenuItem("Java");
              popup.add(menuItem1);
            //books.add(menuItem1);
            menuItem2 = new JMenuItem(".Net");
              popup.add(menuItem2);
              popup.setPopupSize(100,50);
            menuBar = new JMenuBar();
            menuBar.setLayout(new GridLayout(0, 1, 5, 5));
            books.add(popup);
              books.setComponentPopupMenu(popup);
            books.addMouseMotionListener(new MouseMotionAdapter(){
                public void mouseMoved(MouseEvent e)
                     popup.show(books, 88, 0);
              softwares.add(popup);
              softwares.setComponentPopupMenu(popup);
            softwares.addMouseMotionListener(new MouseMotionAdapter(){
                public void mouseMoved(MouseEvent e)
                     popup.show(softwares, 88, 0);
              tools.add(popup);
              tools.setComponentPopupMenu(popup);
            tools.addMouseMotionListener(new MouseMotionAdapter(){
                public void mouseMoved(MouseEvent e)
                     popup.show(tools, 88, 0);
            // p2.add(menuBar);
            p2.add(books);
              p2.add(horizontal1);
              p2.add(softwares);
              p2.add(horizontal2);
              p2.add(tools);
              p2.add(horizontal3);
            p1.add(p2, BorderLayout.WEST);
            content.add(p1);
            setVisible(true);
    }

  • How to make a JPanel with a GridLayout scroll

    I am using a JPanel to hold around 100 buttons. The JPanel is using GridLayout to organise these buttons in rows of 3 buttons per row. i.e. buttonPanel.setLayout(new GridLayout(33,3)); As there are so many buttons they obviously don't all fit in the viewable area of the screen. To get around this I am trying to use a JScrollPane on the buttonPanel to make it scroll but I can't get it to work. I have tried both creating a seperate JScrollPane object and adding the buttonPanel to it
    JScrollPane buttonScroll = new JScrollPane();
    buttonPanel.setLayout(new GridLayout(33,3));
    buttonPanel.setPreferredSize(new Dimension(380,400));
    buttonPanel.setMaximumSize(new Dimension(380,400));
    buttonScroll.add(buttonPanel);and also embeding everything into a new JPanel like:
    buttonHolder.add(new JScrollPane(buttonPanel),BorderLayout.CENTER);Neither way works. Any ideas. I've read about view port but not exactly sure what this is or if this will fix my problem.
    Help urgently required.

    Fixed layouts have their perils.
    We need to figure the size for the buttonScroll. Here's one way to approach this:
        topPanel
            messagePanel 400 x 400    buttonScroll unknown size
        inputPanel
            previewPane  600 x  80    sendButton   icon size (55 x 68, duke)
        For a fixed layout, find the size required for the buttonScroll by commenting out the
        two lines that add the buttons to buttonPanel and calling pack on the frame:
        frame size (pack w/no buttons)     743 x 570
        topPanel size                      735 x 400
        therefore, required size for
            buttonScroll is                335 x 400     (735 - 400, 400)
    After adding the buttons back in the final sizes become
    C:\jexp>java GUI
    frame width = 763       height = 570
    topPanel width = 755    height = 400I substituted a Duke image for your sendIcon so the sizes may differ but this should get you started...
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.Container.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.text.*;
    public class GUI extends JFrame
        Icon sendIcon = new ImageIcon(getClass().getResource("images/T4.gif"));
        Icon deleteIcon = new ImageIcon(getClass().getResource("images/T6.gif"));
        JButton sendButton = new JButton("Send",sendIcon);
        JButton deleteButton = new JButton("Delete",deleteIcon);
        JLabel statusBar = new JLabel();
        JMenu optionsMenu = new JMenu("Options");
        JMenu helpMenu = new JMenu("Help");
        JMenuBar menuBar = new JMenuBar();
        JMenuItem connectMenuItem = new JMenuItem("Connect");
        JMenuItem disconnectMenuItem = new JMenuItem("Disconnect");
        JMenuItem exitMenuItem = new JMenuItem("Exit");
        JMenuItem helpMenuItem = new JMenuItem("Online Help");
        JMenuItem aboutMenuItem = new JMenuItem("About");
        JPanel buttonPanel = new JPanel();
        JPanel inputPanel = new JPanel();
        JPanel messagePanel = new JPanel();
        JPanel topPanel = new JPanel();
        JPanel buttonHolder = new JPanel();
        JScrollPane buttonScroll = new JScrollPane(buttonPanel,20,30);
        JTextPane messageArea = new JTextPane();
        JTextPane previewPane = new JTextPane();
        public GUI()
            super("Chat Program");
            String userName = "user";
            statusBar.setText("Connected: " + userName);
            menuBar.add(optionsMenu);
            menuBar.add(helpMenu);
            setJMenuBar(menuBar);
            optionsMenu.add(connectMenuItem);
            optionsMenu.add(disconnectMenuItem);
            optionsMenu.add(exitMenuItem);
            helpMenu.add(helpMenuItem);
            helpMenu.add(aboutMenuItem);
            buttonPanel.setLayout(new GridLayout(0,3));
            for(int i = 0; i < 100; i++)
                buttonPanel.add(new JButton("Button " + (i + 1)));
            messageArea.setEditable(false);
            previewPane.setEditable(false);
            previewPane.setPreferredSize(new Dimension(600,80));
            previewPane.setMaximumSize(new Dimension(600,80));
            messagePanel.setLayout(new BorderLayout(10,10));
            messagePanel.add(new JScrollPane(messageArea),BorderLayout.CENTER);
            messagePanel.setPreferredSize(new Dimension(400,400));
            messagePanel.setMaximumSize(new Dimension(400,400));
            // w = 735 - 400, h = 400
            // does not take into account the width of the vertical scrollBar
            buttonScroll.setPreferredSize(new Dimension(335,400));       // *
            Box box = new Box(BoxLayout.X_AXIS);
            box.add(new JScrollPane(previewPane));
            box.add(sendButton);
            inputPanel.add(box,BorderLayout.CENTER);
            statusBar.setBorder(new BevelBorder(BevelBorder.LOWERED));
            topPanel.setLayout(new BorderLayout(10,10));
            topPanel.add(messagePanel, BorderLayout.WEST);
            topPanel.add(buttonScroll, BorderLayout.EAST);
            Container content = getContentPane();
            content.add(topPanel,   BorderLayout.NORTH);
            content.add(inputPanel, BorderLayout.CENTER);
            content.add(statusBar,  BorderLayout.SOUTH);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
    //        setSize(?,?);       // 763, 570 (now we know)
            setLocation(200,200);
            setVisible(true);
            // collect size information
            System.out.println("frame width = " + getWidth() + "\t" +
                               "height = " + getHeight() + "\n" +
                               "topPanel width = " + topPanel.getWidth() + "\t" +
                               "height = " + topPanel.getHeight());
        public static void main(String[] args)
            new GUI();
    }

  • JPanel loses keyboard focus

    Ok, i have a JTextField which is initially disabled. A JPanel draws some stuff and receives keyboard input. When i enable the textfield, type some stuff, then press Esc (which disables it), i cant get the keyboard focus back on the JPanel. Here is an example:
    (you can move the red circle before you enable the textfield, after you disable it, you cant move it anymore).
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import java.util.Vector;
    public class example extends JPanel implements ActionListener,Runnable {
        JFrame frame;
        JMenuBar menubar;
        JMenu m_file;
        JMenuItem mi_open,mi_close;
        JPanel canvas,northpanel;
        JTextField textfield;
        Image canvasimg;
        Thread thread=new Thread(this);
        private Image dbImage;     // for flickering
         private Graphics dbg;     // for flickering
         int x1=400,y1=200;
        public example() {
            frame = new JFrame("Example");                         // window
            frame.setLayout(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setPreferredSize(new Dimension(1000,700));
            frame.setLayout(new BorderLayout());
            northpanel=new JPanel();
            northpanel.setLayout(null);
            northpanel.setPreferredSize(new Dimension(1000,20));     northpanel.setLocation(0,0);
            menubar=new JMenuBar();
            m_file=new JMenu("File");   
            mi_open=new JMenuItem("Open");
            mi_close=new JMenuItem("Close");
            m_file.add(mi_open);
            m_file.add(mi_close);   
            m_file.getPopupMenu().setLightWeightPopupEnabled(false);   
            menubar.add(m_file);
            northpanel.add(menubar);
            menubar.setLocation(0,0);     menubar.setSize(80,20);
            textfield=new JTextField();
            northpanel.add(textfield);
            textfield.setSize(200,20);     textfield.setLocation(500,0);   
            textfield.setEnabled(false);
            frame.add(northpanel,BorderLayout.NORTH);
            canvas=new JPanel();
            canvas.setLayout(null);
            canvas.setSize(1000,600);
            canvas.setBackground(Color.white);
             frame.add(canvas,BorderLayout.CENTER);      
            frame.pack();
            frame.setVisible(true);       
            thread.start();                                   // start the thread
            textfield.addMouseListener(new MouseAdapter(){
                    public void mousePressed(MouseEvent e){
                         textfield.setEnabled(true);
               textfield.addKeyListener(new KeyAdapter() {
                 public void keyPressed(KeyEvent e){
                      int key=e.getKeyCode();
                      if(key==27){     // esc
                           textfield.setEnabled(false); 
                           canvas.setEnabled(true);                // not working
                           canvas.requestFocus();
                           canvas.requestFocusInWindow();
               frame.addKeyListener(new KeyAdapter() {
                 public void keyPressed(KeyEvent e){                   
                      int key=e.getKeyCode();
                      if(key==37){ //left
                           x1-=5;
                      if(key==38){ //up
                           y1-=5;
                      if(key==39){ //right
                           x1+=5;
                      if(key==40){ //down
                           y1+=5;
        // Create the GUI and show it. 
        private static void createAndShowGUI() {
            JFrame.setDefaultLookAndFeelDecorated(true);
            example ex = new example();
        public void run(){
             while(true){
                  try{
                       if(canvasimg==null)repaint();                   
                       Graphics g=canvas.getGraphics();
                       update(g);
                       thread.sleep(30);                                             // 1 sec
                  }      catch(InterruptedException ex){}
        // ActionPerformed handles button and menu events
        public void actionPerformed(ActionEvent e){              
        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();
        public void update (Graphics g){          // get rid of flicker
              if (dbImage == null){
                   dbImage = canvas.createImage (canvas.getSize().width, canvas.getSize().height);
                   dbg = dbImage.getGraphics ();
              dbg.setColor (canvas.getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (canvas.getForeground());
              paint (dbg);
              g.drawImage (dbImage, 0, 0, this);
         public void paint(Graphics g){
              g.drawImage(canvasimg,0,0,this);          
              g.setColor(Color.red);
             g.fillOval(x1,y1,10,10);
        public void repaint(){     
             if(canvas!=null && canvasimg==null)canvasimg=canvas.createImage(1000,670);
             if(canvasimg==null)return;
             Graphics g=canvasimg.getGraphics();
             if(g==null)return;
             g.setColor(Color.white);
             g.fillRect(0,0,1000,600);
    }  

    OK great guru since you're so damn confident that you're doing everything right, find out for yourself why this works and yours doesn't.
    I could list a few dozen things wrong with your code, but I'd be wasting my keystrokes.import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class TextFieldDisableNoProblem extends JPanel {
       JPanel northPanel;
       JMenuBar menubar;
       JMenu m_file;
       JMenuItem mi_open,mi_close;
       JTextField textField;
       int x1 = 400;
       int y1 = 200;
       public TextFieldDisableNoProblem () {
          setBackground (Color.WHITE);
          addKeyListener (new KeyAdapter () {
             public void keyPressed (KeyEvent e){
                int key = e.getKeyCode ();
                switch (key) {
                   case KeyEvent.VK_LEFT:
                         x1 -= 5;
                         break;
                   case KeyEvent.VK_UP:
                         y1 -= 5;
                         break;
                   case KeyEvent.VK_RIGHT:
                         x1 += 5;
                         break;
                   case KeyEvent.VK_DOWN:
                         y1 += 5;
                         break;
                repaint ();
       void makeUI () {
          JFrame frame = new JFrame ("");
          frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          frame.setSize (600, 500);
          frame.setLocationRelativeTo (null);
          menubar=new JMenuBar ();
          m_file=new JMenu ("File");
          mi_open=new JMenuItem ("Open");
          mi_close=new JMenuItem ("Close");
          m_file.add (mi_open);
          m_file.add (mi_close);
          menubar.add (m_file);
          frame.setJMenuBar (menubar);
          textField=new JTextField ();
          textField.setEnabled (false);
          textField.setBounds (200, 0, 200, 20);
          textField.addMouseListener (new MouseAdapter (){
             public void mousePressed (MouseEvent e){
                textField.setEnabled (true);
          textField.addKeyListener (new KeyAdapter () {
             public void keyPressed (KeyEvent e){
                int key = e.getKeyCode ();
                if(key == KeyEvent.VK_ESCAPE){
                   textField.setEnabled (false);
                   requestFocus ();
          northPanel=new JPanel ();
          northPanel.setLayout (null);
          northPanel.setPreferredSize (new Dimension (600,20));
          northPanel.add (textField);
          frame.add (northPanel,BorderLayout.NORTH);
          frame.add (this, BorderLayout.CENTER);
          frame.setVisible (true);
          requestFocus ();
       public void paintComponent (Graphics g) {
          super.paintComponent (g);
          g.setColor (Color.RED);
          g.fillOval (x1, y1, 10, 10);
       public static void main (String[] args) {
          SwingUtilities.invokeLater (new Runnable () {
             public void run () {
                JFrame.setDefaultLookAndFeelDecorated (true);
                new TextFieldDisableNoProblem ().makeUI ();
    }db

  • Showing a JPanel

    I'm trying to show a JPanel in my JFrame. Not sure how to accomplish this as I'm new to Swing. Here's my code attached below... Also can you recommend a good book to understand all this.
    public class RMAViewer {
         private static RMAViewer      theApp;
         private static RMAFrame      rmaFrame;
         private static Container      window;
         JPanel aboutPanel = new JPanel();
         public void init() {
              window = new RMAFrame("RMA Inventory Control");
              Toolkit theKit = window.getToolkit();
              Dimension wndSize = theKit.getScreenSize();
              window.setBounds(wndSize.width/4, wndSize.height/4,
         wndSize.width/2, wndSize.height/2);
              window.setVisible(true);
         public static void main(String[] args) {
              theApp = new RMAViewer();
              theApp.init();     
    public class RMAFrame extends JFrame {
         private JMenuBar menuBar = new JMenuBar();
         private JMenuItem closeMenu, scanMenu, aboutMenu;
         private JPanel aboutPanel = new JPanel();
         private Container contentPane = getContentPane();
         private JLabel label = new JLabel("JLabel");
         public RMAFrame(String title) {
              setTitle(title);
              setJMenuBar(menuBar);
              JMenu fileMenu = new JMenu("File");
              JMenuItem closeMenu = fileMenu.add("Close");
              JMenu toolsMenu = new JMenu("Tools");
              JMenuItem scanMenu = toolsMenu.add("Scan");
              JMenu helpMenu = new JMenu("Help");
              JMenuItem aboutMenu = helpMenu.add("About");
              menuBar.add(fileMenu);
              menuBar.add(toolsMenu);
              menuBar.add(helpMenu);     
              enableEvents(AWTEvent.WINDOW_EVENT_MASK);     //enable window events
              aboutPanel.add(new AboutPanel()); doesn't show this.
              aboutPanel.add(label); // shows this.
              aboutPanel.setSize(200,200);
              aboutPanel.setVisible(true);
              setContentPane(aboutPanel);
         //Handle the window events
         protected void processWindowEvent(WindowEvent e) {
              if(e.getID() == WindowEvent.WINDOW_CLOSING) {
                   dispose();               //release resources
                   System.exit(0);          //exit the program
              super.processWindowEvent(e);
    public class AboutPanel extends JPanel {
         Border edge = BorderFactory.createRaisedBevelBorder();
         private JButton okBut;
         private JLabel aboutLabel = new JLabel("RMA Inventory Tracking System");
         private ImageIcon memoryIcon = new ImageIcon("c:/resin/webapps/rma/WEB-INF/classes/com/pdp/memory.gif");
         private JLabel iconLabel = new JLabel(memoryIcon);
         Box boxLayout = Box.createVerticalBox();
         private javax.swing.JButton getbtnOK() {
         if (okBut == null) {
              try {
                   okBut = new javax.swing.JButton();
                   okBut.setName("btnOK");
                   okBut.setMnemonic('o');
                   okBut.setText(" OK ");
                   okBut.setSize(100,100);
                   okBut.setEnabled(true);
                   okBut.setBorder(edge);
                   //okBut.addActionListener(this);
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return okBut;
         public JPanel AboutPanel() {
         JPanel aboutPanel = new JPanel();     
              aboutLabel.setFont(new java.awt.Font("Arial", Font.BOLD, 24));
              boxLayout.add(Box.createVerticalStrut(30));
              aboutLabel.setHorizontalAlignment(SwingConstants.CENTER);
              revLabel.setHorizontalAlignment(SwingConstants.CENTER);
              boxLayout.add(aboutLabel);
              boxLayout.add(iconLabel);
              boxLayout.add(Box.createVerticalStrut(30));
              boxLayout.add(getbtnOK());
              aboutPanel.add(boxLayout);     
              return aboutPanel;
    private void handleException(java.lang.Throwable exception) {
              /* Uncomment the following lines to print uncaught exceptions to stdout */
              // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
              // exception.printStackTrace(System.out);
    }

    Try setContentPane (new AboutPanel ());Kind regards,
    Levi

  • Dynamic jmenu bar

    i have a dynamic JMenu on a jframe. The menu is populated by looking up database entries and ptting them into the right place. This is done by a method 'menus()'.
    I also have an addingredients class which adds new ingredient entries into the database, problem is when it does this, the JMenu has to be repopulated. The following code shows the main frame
    // Recipe Creation GUI
    // Written by Michael Emett
    // Monday 15th Decemeber 2003
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JFrame.*;
    import java.sql.*;
    import java.util.*;
    public class TextAreaDemo extends JFrame     {
    private static JTextArea part1;
    private JButton Browse, Enter, Preview, Remove;
    public static JList printList, newList;
    private JCheckBox pic;
    private JLabel namePrompt, title1, title2, title3;
    private static JTextField nameInput;
    private JPanel jp, jp1, jp2, jp3, jp4, jp5;
    private Connection con;
    private Statement stmt;
    public static JMenu fileMenu;
    private static JMenuBar bar;
    // additions /////////////////////////////////////////////////////////////////////////
    //set up GUI
    public TextAreaDemo()     {
    super( "Recipe Entry Sheet" );
    // set up File menu and its menu items
    // Menu and button Initialization ////////////////////////////////////////////////////
    //myMouse = new MyMouseAdapter();
    //final JMenu
    fileMenu = new JMenu( "Ingredients");
             fileMenu.setMnemonic( 'I' );
    fileMenu.add(menus());
    bar = new JMenuBar();
    setJMenuBar( bar );
    JMenu file = new JMenu( "File");
    file.setMnemonic( 'F' );
        bar.add(file);
              JMenuItem Adder = new JMenuItem( "New Ingredient");
             Adder.setMnemonic( 'N' );
    JMenuItem Subber = new JMenuItem( "New subMenu");
             Subber.setMnemonic( 'S' );
             // set up About... menu item
             JMenuItem aboutItem = new JMenuItem( "About..." );
             aboutItem.setMnemonic( 'A' );
    namePrompt = new JLabel( "Recipe Name " );
    nameInput = new JTextField( 20 );
    title1 = new JLabel( "Selected ingredients" );
    title3 = new JLabel( "Please enter the Recipe Instructions" );
    title2 = new JLabel( "Enter The SubMenu Name " );
    pic = new JCheckBox("Add Picture", false);
    file.add( Adder );
         Adder.addActionListener(
              new ActionListener()     {
                    public void actionPerformed( ActionEvent event )
                        getList f = new getList();
    // Add Ingredient menu item //////////////////////////////////////////////////////////
    file.add( Subber );
         Subber.addActionListener(
              new ActionListener()     {
                    public void actionPerformed( ActionEvent event )
                        AddSubMenu f = new AddSubMenu();
    // About menu item ///////////////////////////////////////////////////////////////////
    file.add( aboutItem );
          aboutItem.addActionListener(
             new ActionListener() {  // anonymous inner class
                // display message dialog when user selects About...
                public void actionPerformed( ActionEvent event )
                   JOptionPane.showMessageDialog( TextAreaDemo.this,
                      "Developed by Michael Emett, 2004",
                      "About", JOptionPane.PLAIN_MESSAGE );
              }     // end anonymous inner class
         );  // end call to addActionListener
    // Exit menu item ////////////////////////////////////////////////////////////////////
         JMenuItem exitItem = new JMenuItem( "Exit" );
         exitItem.setMnemonic( 'x' );
         file.add( exitItem );
          exitItem.addActionListener(
             new ActionListener() {  // anonymous inner class
                // terminate application when user clicks exitItem
                public void actionPerformed( ActionEvent event )
                   System.exit( 0 );
             }  // end anonymous inner class
          ); // end call to addActionListener
    //create Button Enter
    Enter = new JButton("Enter");
    Enter.addActionListener(
              new ActionListener()     {
                              public void actionPerformed( ActionEvent event )
                        StringBuffer a = new StringBuffer();
                        StringBuffer b = new StringBuffer();
                        StringBuffer c = new StringBuffer();
                        for(int i= 0; i< victor.size(); i++){
                        b.append(victor.elementAt(i));
                        b.append("; ");
                        a.append(nameInput.getText());
                        c.append(part1.getText());
                        //System.out.println(a);
                        //System.out.println(b);
                        //System.out.println(c);
                        InsertRecipe f = new InsertRecipe(a,b,c);
                        //invalidate();
                //fileMenu.updateUI();
               // fileMenu.revalidate();
    //create Button Remove
    Remove = new JButton("Remove");
    //add Actionlistener
    Remove.addActionListener(
              new ActionListener()     {
                    public void actionPerformed( ActionEvent event )
    int[] arr;
    arr = printList.getSelectedIndices();
    int counter = 0;
         for (int i= 0; i< arr.length; i++){
              int n=arr;
              victor.remove(n-counter);
              counter++;
    printList.setListData(victor);
    //create Button Remove
    Browse = new JButton("Browse");
    //create Button Preview
    Preview = new JButton("Clear");
    Preview.addActionListener(
    new ActionListener() {  // anonymous inner class
    // display message dialog when user selects Preview...
    public void actionPerformed( ActionEvent event )
    int result = JOptionPane.showConfirmDialog
                             (null,      "Are you sure to want to clear this form", "Clear?",      JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);
                             if(result == JOptionPane.YES_OPTION)
                             {TextAreaDemo.clear();
                                  //System.out.println("Recipe Entered");
              }//end of joptionpane
    printList = new JList();
    printList.setVisibleRowCount(9);
    printList.setFixedCellWidth(150);
    printList.setFixedCellHeight(15);
    printList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
    newList = new JList();
    newList.setVisibleRowCount(9);
    newList.setFixedCellWidth(150);
    newList.setFixedCellHeight(15);
    newList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION );
    // Initialise Text Areas //
    part1 = new JTextArea( 25, 50);
    part1.setFont(new Font("Courier", Font.BOLD, 12));
    part1.setLineWrap(true);
    part1.setWrapStyleWord(true);
    // JPanels for Layout //
    jp = new JPanel();
    jp1 = new JPanel();
    jp2 = new JPanel();
    jp3 = new JPanel();
    jp4 = new JPanel();
    jp5 = new JPanel();
    final Container c = getContentPane();
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
         c.setLayout(gbl);
         gbc.weightx = 0.1;
         gbc.weighty = 0.5;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    add(jp1, gbc, 0, 0, 1, 1);
    gbc.fill = GridBagConstraints.NONE;
    add(jp2, gbc, 0, 1, 1, 1);
    add(jp3, gbc, 1, 0, 2, 2);
    jp1.add(jp4, BorderLayout.CENTER);
    jp2.add(jp, BorderLayout.CENTER);
    bar.add( namePrompt );
    bar.add( nameInput);
    bar.add( fileMenu );
    jp4.setLayout(new BorderLayout());
    jp4.add(title1, BorderLayout.NORTH);
    jp4.add(new JScrollPane( printList), BorderLayout.CENTER);
    jp4.add(Remove, BorderLayout.SOUTH);
    jp.setLayout(new BorderLayout());
    jp.add(pic, BorderLayout.NORTH);
    jp.add(new JScrollPane (newList), BorderLayout.CENTER);
    jp.add(Browse, BorderLayout.SOUTH);
    jp3.setLayout(new BorderLayout());
    jp3.add (title3, BorderLayout.NORTH);
    jp3.add (new JScrollPane(part1), BorderLayout.CENTER);
    //c.addMouseListener(myMouse);
    gbc.anchor = GridBagConstraints.LAST_LINE_END;
    add(jp5, gbc, 2, 3, 1, 1);
    jp5.setLayout(new FlowLayout());
    jp5.add(Preview);
    jp5.add(Enter);
    setSize(770, 620);
         pack();
         setVisible(true);
         setResizable(false);
    private static Vector victor = new Vector();
    public static void printListset(String t) {
         victor.add(t);
    for(int i = 0; i<victor.size(); i++)
    printList.setListData(victor);
    public void add(Component ce, GridBagConstraints constraints, int x, int y, int w, int h) {
                   constraints.gridx = x;
                   constraints.gridy = y;
                   constraints.gridwidth = w;
                   constraints.gridheight = h;
                   getContentPane().add(ce, constraints);
    public static JMenu menus()     {
         // Map Created to Handle JMenuItem Addition //
              Map labelToMenu = new HashMap();
              Map labelToMenu2 = new HashMap();
              Map labelToMenu3 = new HashMap();
              String url = "jdbc:odbc:database";
              Connection con;
              Statement stmt;
                        try     {
                             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                        catch(ClassNotFoundException e)     {
                        System.err.print("Class Not found");
                        String query = "select baseIngred.IngredientType, baseIngred.PrimaryKey FROM baseIngred";
                        String query2 = "select baseIngred.IngredientType, baseIngred.PrimaryKey,"
                        + "subMenu.menuNumber, subMenu.subMenu FROM baseIngred, "
                        + "subMenu WHERE baseIngred.PrimaryKey = subMenu.menuNumber ORDER BY submenu";
                                  String query3 = "select subMenu.subMenu, subMenu.PrimaryNumber,"
                                       + "Ingredient.Ingredient, Ingredient.MenuNumber FROM subMenu, Ingredient"
                        + " WHERE Ingredient.MenuNumber = subMenu.PrimaryNumber ORDER BY PrimaryNumber";
         String query4 = "select Ingredient.Ingredient, Ingredient.MenuNumber FROM Ingredient";
                             try     {
                                       con = DriverManager.getConnection(url, "myLogin", "myPassword");
                                       stmt = con.createStatement();
         // Initial Jmenu added ///////////////////////////////////////////////////////////////
                   ResultSet rs = stmt.executeQuery(query);
                   String[] arr = new String[100];
                   int[] num = new int[200];
                   int[] num2 = new int[200];
                   int counter = 0;
                   int counter2 = 0;
                   while     (rs.next())     {
                                  //String t is set to the value contained in ingredient type
                                  String t = rs.getString("IngredientType");
                                  //map labelToMenu has String t and a new JMenu with the menu
                                  //name contained in t stored in it
                                  labelToMenu.put(t, fileMenu.add(new JMenu(t)));
                                  //an array containing values of the priamry key is produced
                                  num[counter] = rs.getInt("PrimaryKey");
                                  //a counter is incremeted so that upon further
                                  //interations it is stored in a new array field
                                  counter++;
         // Second Jmenu added ////////////////////////////////////////////////////////////////
                   ResultSet rs2 = stmt.executeQuery(query2);
                   while     (rs2.next()) {
                                  //String first is set to the value contained in ingredient type
                                  String first = rs2.getString("IngredientType");
                                  //String second is set to the value contained in subMenu
                                  String second = rs2.getString("subMenu");
                                  //firstlevel looks up item t in the map, and creates a jmenu name as it.
                                  JMenu firstLevel = (JMenu)labelToMenu.get(first);
                                  //handles menu placement by comparing PrimaryKeys with MenuNumbers
                                  // f = rs2.getInt("menuNumber");
                                  num2[counter2] = rs2.getInt("menuNumber");
         for (int nm = 0; nm<num.length; nm++){
                   if (num[nm] == num2[counter2]
                                            //adds the second value to the jmenu with th name stored in t.
                                            labelToMenu2.put(second, (firstLevel.add(new JMenu (second))));
                                       }counter2++;
         // Third JMenu added /////////////////////////////////////////////////////////////////
         ResultSet rs3 = stmt.executeQuery(query3);
              while     (rs3.next()) {
                                  //String next is set to the value contained in subMenu
                                  String next = rs3.getString("subMenu");
                                  //String third is set to the value contained in ingredient
                                  String third = rs3.getString("Ingredient");
                                  JMenu secondLevel = (JMenu)labelToMenu2.get(next);
                                  int f2 = rs3.getInt("MenuNumber");
                                  //System.out.println(f2);
                                  int f3 = rs3.getInt("PrimaryNumber");
                   if (f3 == f2){
                             labelToMenu3.put(third, secondLevel.add(new JMenuItem(third)));
         // Add AtionListeners ////////////////////////////////////////////////////////////////
         ResultSet rs4 = stmt.executeQuery(query4);
              while     (rs4.next()) {
                   String third2 = rs4.getString("Ingredient");
         JMenuItem thirdLevel = (JMenuItem)labelToMenu3.get(third2);
         thirdLevel.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                   JMenuItem source = (JMenuItem)(e.getSource());
                   String actionText = source.getText();
                   PopUp pop = new PopUp(actionText);
                        stmt.close();
                        con.close();
                             }catch(SQLException ex)     {
                        System.err.println(ex);
    return (fileMenu);
         //                                        End Of Connection                                             //
         // Add subMenu menu item /////////////////////////////////////////////////////////////
    public static void clear()     {
    nameInput.setText("");
    victor.removeAllElements();
    printList.setListData(victor);
    part1.setText("");
    public static void rebuild()     {
    fileMenu.removeAll();
    fileMenu.add(menus());
    bar.add( fileMenu );
    public static void main(String args[])     {
         TextAreaDemo t = new TextAreaDemo();
         t.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
    the code inside the method 'rebuild()' will work from inside the main JFrame body if assigned to a button (such as the example position denoted by HERE in the code), but that is undesirable as it requires the user to refresh manually every time they add a new ingredient. what i need is a method that can be called from another class/method/whatever.
    thankyou for any help you can offer, it is much appreciated

    The code you offered did not solve my problem. I have since entered the followinginto the actionlistener of a button on the JFrame,
    refreshMenu = new JButton("Refresh Menu");
    refreshMenu.addActionListener(
             new ActionListener() { 
                // display message dialog when user selects Preview...
                public void actionPerformed( ActionEvent event )
    fileMenu.removeAll();
    fileMenu.add(menus());
    bar.add( fileMenu );          
    );This does what i need, but i need these statements to be made from an external class, not a JButton,

  • HELP!!!  Adding JPanel to JPanel (long code sample)

    I need some help here. I have been stuck on this for more time than I care to admit. Now this project is due by Monday(tomorrow)! Why does the graph not appear in the tabbed pane "trend report"?? the TrendReport class on line 2131 creates the graph. Line 56 creates an instance. and line 831 adds it to the tabbed pane. everything shows up except the graph.
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.text.*;
    import java.util.*;
    import java.lang.*;
    import javax.swing.JPopupMenu;
    import javax.swing.JPanel;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JLabel;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.JTable;
    import javax.swing.filechooser.*;
    /*<br>
    *A332IWon Class<br>
    *CIS 32 / Cuesta College<br>
    *Assignment     3<br>
    *Due Date 10-08-03<br>
    *<br>
    *<br>
    *<br> >>>>>>>>> Start filling in your class discription here <<<<<<<<<<<<
            >>>>>>>>> And Start filling in your method discriptions <<<<<<<<<<<
    *<br>
    *<br>@author<br>
    *Chris Hoffman, Michael Krempely, Rudy Kalnin, Scott Thayer and Frank Randise<br>
    *@version 10.16<br>
    *<br>
    *<br>
    public class A332IWon extends JFrame
         * Class to handle all data input, output, sorting and display handling.
        private A332IWonEngine engine = new A332IWonEngine();
          * Instance of the inner class "QuickTable" called "quickTabke"
         private QuickTable quickTable = new QuickTable();
          * Instance of the inner class "BasicPayTable" called "basicPayTable"
        private BasicPayTable basicPayTable = new BasicPayTable();
         * Instance of the inner class "TrendReport" called "trendReport"
        private TrendReport trendReport = new TrendReport();       
          * Container that holds all panels, labels, and text fields
         private Container c = getContentPane();
          * The menu bar at the top of the application
         private JMenuBar bar = new JMenuBar();
          * Menu bar header called "File"
         private JMenu menuFile = new JMenu("File");
          * Menu bar header called "Edit"
         private JMenu menuEdit = new JMenu("Edit");
          * Menu bar header called "Reports"
        private JMenu menuReports = new JMenu("Reports");
          * Menu bar header called "Help"
        private JMenu menuHelp = new JMenu("Help");
          * Menu item called "Import" a sub menu item of "menuFile"
         private JMenuItem fileImport = new JMenu("Import");
          * Menu item called "Employee Text File" a sub menu item of "fileImport"
          * which in turn is a sub item of "menuFile"
         private JMenuItem fileEmpTxtFile = new JMenuItem("Employee Text File");
          * Menu item called "Pay Info File" a sub menu item of "fileImport"
          * which in turn is a sub item of "menuFile"
         private JMenuItem filePayInfoFile = new JMenuItem("Pay Info File");
          * Menu item called "Open" a sub menu item of "menuFile"
           private JMenuItem fileOpen = new JMenuItem("Open");
          * Menu item called "Save" a sub menu item of "menuFile"
           private JMenuItem fileSave = new JMenuItem("Save");
          * Menu item called "Exit" a sub menu item of "menuFile"
           private JMenuItem fileExit = new JMenuItem("Exit");
          * Menu item called "Search" a sub menu item of "menuEdit"
          private JMenuItem editSearch = new JMenu("Search");
          * Menu item called "Add/Remove" a sub menu item of "menuEdit"
           private JMenuItem editAddRemove = new JMenuItem("Add/Remove");
          * Menu item called "By ID #" a sub menu item of "editSearch"
          * which in turn is a sub item of "menuEdit"
           private JMenuItem editID = new JMenuItem("By ID #");
          * Menu item called "By name" a sub menu item of "editSearch"
          * which in turn is a sub item of "menuEdit"
           private JMenuItem editName = new JMenuItem("By name");
          * Menu item called "Basic Pay" a sub menu item of "menuReports"
           private JMenuItem repBasicPay = new JMenuItem("Basic Pay");
          * Menu item called "Trend" a sub menu item of "menuReports"
           private JMenuItem repTrend = new JMenuItem("Trend");
          * Menu item called "About" a sub menu item of "menuHelp"
           private JMenuItem helpAbout = new JMenuItem("About");
          * The tabbed pane that holds our table, reports and table editing capabilities
         private JTabbedPane empInfoTabPane = new JTabbedPane();
          * Main panel located in center that holds the tabbed pane "empInfoTabPane"
         private JPanel pCenterMain = new JPanel(new FlowLayout(FlowLayout.LEFT,25,30));
          * Panel that holds the table "table"
         private JPanel pTable = new JPanel(new GridLayout(2,1));
          * Main panel that holds the Basic Pay Report(s)
         private JPanel pBasicPayRep = new JPanel(new FlowLayout(FlowLayout.CENTER,10,20));
          * Main panel that holds the Trend Report(s)
         private JPanel pTrendRep = new JPanel(new FlowLayout(FlowLayout.CENTER,10,10));
          * Panel that holds all the add/remove fields, combo boxes and buttons
         private JPanel pAddRemove = new JPanel(new GridLayout(2,1));
            * Panel and Labels for Basic Pay Report
           private JPanel pBasicPayRepMain = new JPanel(new GridLayout(2,1));
          * Holds the pBasicPayGridLeft and pBasicPayGridRight
         private JPanel pBasicPayRepBot = new JPanel(new FlowLayout(FlowLayout.CENTER));
          * Holds the labels for each report
          * Recent Pay Period Worked, Cumulative Pay, Average Pay
         private JPanel pBasicPayGridLeft = new JPanel(new FlowLayout(FlowLayout.LEFT));
          * Holds all the basic pay report information for
          * Recent Pay Period Worked, Cumulative Pay, Average Pay
         private JPanel pBasicPayGridRight = new JPanel(new FlowLayout(FlowLayout.LEFT,20,0));
          * Displays the total number of employees that worked in the current pay period
         private JLabel txtTotalAllEmployees = new JLabel("0");
          * Displays the total number of Salaried employees that worked in the current pay period
         private JLabel txtTotalSalaried = new JLabel("0");
          * Displays the total number of Hourly employees that worked in the current pay period
         private JLabel txtTotalHourly = new JLabel("0");
          * Displays the total number of Temporary employees that worked in the current pay period
         private JLabel txtTotalTemporary = new JLabel("0");
          * Displays the total number of Contract employees that worked in the current pay period
         private JLabel txtTotalContract = new JLabel("0");
          * Displays the cumulative hourly rate in the current pay period
         private JLabel txtCumHourlyRate = new JLabel("0.00");
          * Displays the cumulative hours workded in the current pay period
           private JLabel txtCumHoursWorked = new JLabel("0");
          * Displays the cumulative gross pay in the current pay period
           private JLabel txtCumGrossPay = new JLabel("0.00");
          * Displays the cumulative tax paid in the current pay period
           private JLabel txtCumTax = new JLabel("0.00");
          * Displays the cumulative net pay in the current pay period
           private JLabel txtCumNetPay = new JLabel("0.00");
          * Displays the average hourly rate in the current pay period
           private JLabel txtAvgHourlyRate = new JLabel("0.00");
          * Displays the average hours workded in the current pay period
           private JLabel txtAvgHoursWorked = new JLabel("0.0");
          * Displays the average gross pay in the current pay period
           private JLabel txtAvgGrossPay = new JLabel("0.00");
          * Displays the average tax paid in the current pay period
           private JLabel txtAvgTax = new JLabel("0.00");
          * Displays the average net pay in the current pay period
           private JLabel txtAvgNetPay = new JLabel("0.00");
          * The table "table" created in the instance "quickTable"
         private JTable table = new JTable(quickTable);
          * The table "table2" created in the instance "BasicPayTable"
         private JTable table2 = new JTable(basicPayTable);
          * Turns the table "table" into a scroll pane
        private JScrollPane scrollpane = new JScrollPane(table);
          * Turns the table "table2" into a scroll pane2
        private JScrollPane scrollpane2 = new JScrollPane(table2);
          * **** Future Button to update the employee information in "table"
        private JButton updateEmplInfo = new JButton("Update");
         * Add button to add an employee
        private JButton bAdd = new JButton("Add");
         * Remove button to remove an employee
         private JButton bRemove = new JButton("Remove");
         * Search by employee ID button
         private JButton bSearchId = new JButton("Search");
         * Search by employee name button
         private     JButton bSearchName = new JButton("Search");
         * Texfield collects an employees ID number
        private JTextField fieldID = new JTextField(6);
         * Texfield collects an employees Last name
         private JTextField fieldLastName = new JTextField(22);
         * Texfield collects an employees First name
         private JTextField fieldFirstName = new JTextField(15);
         * Texfield collects an employees Middle initial
         private JTextField fieldMiddleInitial = new JTextField(1);
         * Texfield collects an employees street address
         private JTextField fieldStreetAddress = new JTextField(22);
         * Texfield collects an employees city lived in
         private JTextField fieldCity = new JTextField(18);
         * Texfield collects an employees state lived in
         private JTextField fieldState = new JTextField(2);
         * Texfield collects an employees zip code
         private JTextField fieldZip = new JTextField(6);
         * Texfield collects an employees hourly rate
         private JTextField fieldHourlyRate = new JTextField("0.00",6);
         * Texfield collects an employees year they started working
         private JTextField fieldYYYY = new JTextField("YYYY",4);
         * Texfield collects an employees ID number to perform a search with
         private JTextField fieldSearchById = new JTextField(6);
         * Texfield collects an employees last name to perform a search with
         private JTextField fieldSearchByLast = new JTextField(22);
         * Texfield collects an employees first name to perform a search with
         private     JTextField fieldSearchByFirst = new JTextField(15);
         * Texfield collects an employees middle initial to perform a search with
         private     JTextField fieldSearchByMiddle = new JTextField(1);
          * Background color designed to mimic Microsofts's default desktop color
         private Color MS = new Color(64,128,128);
         * Color used to simulate a manilla folder
         * <br>Used on the folders
         private Color manilla = new Color(252,220,140);
         * Color a complimenting color to "manilla" and "MS"
         * <br>Used as an accent in the search frames and tabs
         private Color seaFoam = new Color(156,198,172);
         * Color a complimenting color to "manilla" and "MS"
         * <br>Used as an accent in the tabs
         private Color babyBlue = new Color(170,220,238);
         * Color a complimenting color to "manilla" and "MS"
         * <br>Used as an accent in the tabs
         private Color lightPink = new Color(255,204,207);
         * Array of Strings: the 12 months of the year
         private String [] monthMM = {"MM","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
                                             "Sep","Oct","Nov","Dec"};
         * Array of Strings: the days of the month
         private String [] dayDD = {"DD","01","02","03","04","05","06","07","08","09","10","11",
                                          "12","13","14","15","16","17","18","19","20","21","22",
                                          "23","24","25","26","27","28","29","30","31"};
         * Array of Strings: employee types
         * <br>"Salaried","Hourly","Temporary","Contract"
         private String [] emplType = {"Emp Type","Salaried","Hourly","Temporary","Contract"};
         * String holds the month by using getSelectedItem()
         private String sMonth = "";
         * String holds the day by using getSelectedItem()
         private String sDay = "";
         * String holds the entire hire date
         private String sHireDate = "";
         * String holds the entire employee address
         private String sEmpAddress = "";
         * Double the horly rate paid to an employee
         private double hourlyRate = 0.0;
         * Drop down combo box displays the months of the year
        private JComboBox listMM = new JComboBox(monthMM);
         * Drop down combo box displays the days of the month
         private JComboBox listDD = new JComboBox(dayDD);
         * Drop down combo box displays the employee types
         private JComboBox listEmplType = new JComboBox(emplType);
         private JPanel pTrendReportMain = new JPanel();
         private JPanel pTrendReport = new JPanel();
         private JPanel pTrendRepMain = new JPanel(new GridLayout(2,1));
         private JPanel pTrendBot = new JPanel(new FlowLayout(FlowLayout.CENTER));
         private JPanel pTrendGridLeft = new JPanel(new FlowLayout(FlowLayout.LEFT));
         private JPanel pTrendGridRight = new JPanel(new FlowLayout(FlowLayout.LEFT,20,0));
         private JButton button, button2;
         private JLabel []JLab = new JLabel[4];
         private JTextField titletxt;
         private JTextField []Text = new JTextField[5];
         private JTextField []labeltxt = new JTextField[5];
         private JLabel txtTrendTotalEmployees = new JLabel("0");
         private JLabel txtTrendCumHourlyRate = new JLabel("0.00");
         private JLabel txtTrendAvgHourlyRate = new JLabel("0.00");
         private JLabel txtTrendTotalSalaried = new JLabel("0");
         private JLabel txtTrendCumHoursWorked = new JLabel("0");
         private JLabel txtTrendAvgHoursWorked = new JLabel("0.0");
         private JLabel txtTrendTotalHourly = new JLabel("0");
         private JLabel txtTrendCumGrossPay = new JLabel("0.00");
         private JLabel txtTrendAvgGrossPay = new JLabel("0.00");
         private JLabel txtTrendTotalTemporary = new JLabel("0");
         private JLabel txtTrendCumTax = new JLabel("0.00");
         private JLabel txtTrendAvgTax = new JLabel("0.00");
         private JLabel txtTrendTotalContract = new JLabel("0");
         private JLabel txtTrendCumNetPay = new JLabel("0.00");
         private JLabel txtTrendAvgNetPay = new JLabel("0.00");
         //Don't know if we can use these yet
         //private JLabel lPayPeriodStart = new JLabel("YYYY MM PP");
         //private JLabel lPayPeriodEnd = new JLabel("YYYY MM PP");
          * Standard constructor
          * <br>Call the main methods required to get the application to start
         public A332IWon(String title)
              super(title);
              menuDialogBar();
              setUpPanels();
              setContainerLayout();
              listenToMenuBar();
              listenToButtons();
              addWindowListener(new CloseWindow());
          * Contains all the ActionListener events associated with the menu bar
         public void listenToMenuBar()
              fileEmpTxtFile.addActionListener(quickTable);
              filePayInfoFile.addActionListener(quickTable);
              fileOpen.addActionListener(quickTable);
              fileSave.addActionListener(quickTable);
              fileExit.addActionListener(quickTable);
              editAddRemove.addActionListener(quickTable);
              editID.addActionListener(quickTable);
              editName.addActionListener(quickTable);
              repBasicPay.addActionListener(quickTable);
              repTrend.addActionListener(quickTable);
              helpAbout.addActionListener(quickTable);
          * Contains all ActionListener events associated with buttons and combo boxes
         public void listenToButtons()
              bAdd.addActionListener(quickTable);
              bRemove.addActionListener(quickTable);
              listMM.addActionListener(quickTable);
              listDD.addActionListener(quickTable);
              listEmplType.addActionListener(quickTable);
              bSearchId.addActionListener(quickTable);
              bSearchName.addActionListener(quickTable);
          * Contains the menu bar, the menus, and all the sub menu items
         public void menuDialogBar()
               JLabel menuShim = new JLabel("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
                                                 + "XXXXXXXXXXXXXXXXXXXXXXx12345");
               setJMenuBar(bar);
               bar.add(menuFile);
               bar.add(menuEdit);
               bar.add(menuReports);
               bar.add(menuHelp);
               bar.add(menuShim);
               menuShim.setVisible(false);
               menuFile.add(fileImport);
               fileImport.add(fileEmpTxtFile);
               fileImport.add(filePayInfoFile);
               menuFile.add(fileOpen);
               menuFile.add(fileSave);
               menuFile.add(fileExit);
               menuEdit.add(editAddRemove);
               menuEdit.add(editSearch);
               editSearch.add(editID);
               editSearch.add(editName);
               menuReports.add(repBasicPay);
               menuReports.add(repTrend);
               menuHelp.add(helpAbout);
          * Sets the layout for the container "c" and sets pCenterMain centered in "c"
         public void setContainerLayout()
              c.setLayout(new BorderLayout());
              c.add(pCenterMain, "Center");
          * Sets up the main panels needed at run time
         public void setUpPanels()
              centerMainPanel();
              tabbedPane();
              tabPanels();
              addRemovePanel();
              basicPayReportMain();
              trendReportMain();
          * Sets up the main panel with the tabbed pane "empInfoTabPane"
         public void centerMainPanel()
              pCenterMain.add(empInfoTabPane);
              pCenterMain.setBackground(MS);
          * Sets up the tabbed pane with the table, and eddit block,
          * basic pay report, and trend report
         public void tabbedPane()
             empInfoTabPane.addTab("Employee Information",pTable);
             empInfoTabPane.addTab("Basic Pay Report",pBasicPayRep);
             empInfoTabPane.addTab("Trend Report",pTrendRep);
             //empInfoTabPane.setBackground(manilla);
             //empInfoTabPane.setBackgroundAt(0,manilla);
             empInfoTabPane.setBackgroundAt(0,seaFoam);
             empInfoTabPane.setBackgroundAt(1,lightPink);
             empInfoTabPane.setBackgroundAt(2,babyBlue);
             //AUTO_RESIZE_OFF
             //empInfoTabPane.setEnabledAt(0,false);
          * Sets up the panels in the tabbed pane
         public void tabPanels()
              //JLabel tabTrendRep = new JLabel("This area will show a Trend report");
             JPanel pTableTop = new JPanel(new FlowLayout(FlowLayout.CENTER,20,20));
             JPanel pTableBottom = new JPanel(new FlowLayout(FlowLayout.LEFT));
              scrollpane.setPreferredSize(new Dimension(695,185));
              scrollpane2.setPreferredSize(new Dimension(695,185));
              pTableTop.add(scrollpane);
              pTableBottom.add(pAddRemove);
              pTableTop.setBackground(manilla);
              pTableBottom.setBackground(manilla);
              pTable.add(pTableTop);
              pTable.add(pTableBottom);
              pBasicPayRep.add(pBasicPayRepMain);
             pBasicPayRep.setBackground(manilla);
             pTrendRep.add(pTrendRepMain);
             pTrendRep.setBackground(manilla);
          * Sets up the basic pay report main panel that holds the table and the bottom pay report
         public void basicPayReportMain()
              pBasicPayRepMain.add(scrollpane2);
              pBasicPayRepMain.add(pBasicPayRepBot);
              basicPayRepTotalsPanel();
          * Sets up the basic pay report grid panel under the basic pay report table.
         public void basicPayRepTotalsPanel()
              JPanel pBasicPayLeftRight = new JPanel(new FlowLayout(FlowLayout.CENTER,10,5));
                pBasicPayRepBot.add(pBasicPayLeftRight);
                pBasicPayRepBot.setBackground(manilla);
                pBasicPayLeftRight.add(pBasicPayGridLeft);
                pBasicPayLeftRight.add(pBasicPayGridRight);
                pBasicPayLeftRight.setBackground(manilla);
                basicPayGridLeft();
                basicPayGridRight();
          * Sets up the left grid of the basic pay report grid panel.
         public void basicPayGridLeft()
              JPanel pColumn1 = new JPanel(new GridLayout(10,1));
              JLabel lblTotalEmployees = new JLabel("Recent Pay Period Worked");
              JLabel lblCumulativePay = new JLabel("Cumulative Pay");
              JLabel lblAveragePay = new JLabel("Average Pay");
              JLabel lblShim1 = new JLabel("X");
              JLabel lblShim2 = new JLabel("X");
              JLabel lblShim3 = new JLabel("X");
              lblShim1.setForeground(manilla);
              lblShim2.setForeground(manilla);
              lblShim3.setForeground(manilla);
              pColumn1.add(lblTotalEmployees);
              pColumn1.add(lblShim1);
              pColumn1.add(new JLabel(" "));
              pColumn1.add(new JLabel(" "));
              pColumn1.add(lblCumulativePay);
              pColumn1.add(lblShim2);
              pColumn1.add(new JLabel(" "));
              pColumn1.add(new JLabel(" "));
              pColumn1.add(lblAveragePay);
              pColumn1.add(lblShim3);
              pColumn1.setBackground(manilla);
              lblTotalEmployees.setForeground(Color.black);
              lblCumulativePay.setForeground(Color.black);
              lblAveragePay.setForeground(Color.black);
              pBasicPayGridLeft.add(pColumn1);
              pBasicPayGridLeft.setBackground(manilla);
          * Sets up the right grid of the basic pay report grid panel.
          * <br>This is one narly method
         public void basicPayGridRight()
              JPanel pColumn1 = new JPanel(new GridLayout(10,1));
              JPanel pColumn2 = new JPanel(new GridLayout(10,1));
              JPanel pColumn3 = new JPanel(new GridLayout(10,1));
              JPanel pColumn4 = new JPanel(new GridLayout(10,1));
              JPanel pColumn5 = new JPanel(new GridLayout(10,1));
                JLabel lblTotalEmployees = new JLabel("Employees");
                JLabel lblTotalSalaried = new JLabel("Salaried");
                JLabel lblTotalHourly = new JLabel("Hourly");
                JLabel lblTotalTemporary = new JLabel("Temporary");
                JLabel lblTotalContract = new JLabel("Contract");
                JLabel lblCumHourlyRate = new JLabel("Pay Rate");
                JLabel lblCumHoursWorked = new JLabel("Hours Worked");
                JLabel lblCumGrossPay = new JLabel("Gross Pay");
                JLabel lblCumTax = new JLabel("Flat Tax 15%");
                JLabel lblCumNetPay = new JLabel("Net Pay");
                JLabel lblAvgHourlyRate = new JLabel("Pay Rate");
                JLabel lblAvgHoursWorked = new JLabel("Hours Worked");
                JLabel lblAvgGrossPay = new JLabel("Gross Pay");
                JLabel lblAvgTax = new JLabel("Flat Tax 15%");
                JLabel lblAvgNetPay = new JLabel("Net Pay");
              pColumn1.add(lblTotalEmployees);
              pColumn1.add(txtTotalAllEmployees);
              pColumn1.add(new JLabel(" "));
              pColumn1.add(new JLabel(" "));
              pColumn1.add(lblCumHourlyRate);
              pColumn1.add(txtCumHourlyRate);
              pColumn1.add(new JLabel(" "));
              pColumn1.add(new JLabel(" "));
              pColumn1.add(lblAvgHourlyRate);
              pColumn1.add(txtAvgHourlyRate);
              pColumn1.setBackground(manilla);
              lblTotalEmployees.setForeground(Color.black);
              txtTotalAllEmployees.setForeground(Color.black);
              lblCumHourlyRate.setForeground(Color.black);
              txtCumHourlyRate.setForeground(Color.black);
              lblAvgHourlyRate.setForeground(Color.black);
              txtAvgHourlyRate.setForeground(Color.black);
              pColumn2.add(lblTotalSalaried);
              pColumn2.add(txtTotalSalaried);
              pColumn2.add(new JLabel(" "));
              pColumn2.add(new JLabel(" "));
              pColumn2.add(lblCumHoursWorked);
              pColumn2.add(txtCumHoursWorked);
              pColumn2.add(new JLabel(" "));
              pColumn2.add(new JLabel(" "));
              pColumn2.add(lblAvgHoursWorked);
              pColumn2.add(txtAvgHoursWorked);
              pColumn2.setBackground(manilla);
              lblTotalSalaried.setForeground(Color.black);
              txtTotalSalaried.setForeground(Color.black);
              lblCumHoursWorked.setForeground(Color.black);
              txtCumHoursWorked.setForeground(Color.black);
              lblAvgHoursWorked.setForeground(Color.black);
              txtAvgHoursWorked.setForeground(Color.black);
              pColumn3.add(lblTotalHourly);
              pColumn3.add(txtTotalHourly);
              pColumn3.add(new JLabel(" "));
              pColumn3.add(new JLabel(" "));
              pColumn3.add(lblCumGrossPay);
              pColumn3.add(txtCumGrossPay);
              pColumn3.add(new JLabel(" "));
              pColumn3.add(new JLabel(" "));
              pColumn3.add(lblAvgGrossPay);
              pColumn3.add(txtAvgGrossPay);
              pColumn3.setBackground(manilla);
              lblTotalHourly.setForeground(Color.black);
              txtTotalHourly.setForeground(Color.black);
              lblCumGrossPay.setForeground(Color.black);
              txtCumGrossPay.setForeground(Color.black);
              lblAvgGrossPay.setForeground(Color.black);
              txtAvgGrossPay.setForeground(Color.black);
              pColumn4.add(lblTotalTemporary);
              pColumn4.add(txtTotalTemporary);
              pColumn4.add(new JLabel(" "));
              pColumn4.add(new JLabel(" "));
              pColumn4.add(lblCumTax);
              pColumn4.add(txtCumTax);
              pColumn4.add(new JLabel(" "));
              pColumn4.add(new JLabel(" "));
              pColumn4.add(lblAvgTax);
              pColumn4.add(txtAvgTax);
              pColumn4.setBackground(manilla);
              lblTotalTemporary.setForeground(Color.black);
              txtTotalTemporary.setForeground(Color.black);
              lblCumTax.setForeground(Color.black);
              txtCumTax.setForeground(Color.black);
              lblAvgTax.setForeground(Color.black);
              txtAvgTax.setForeground(Color.black);
              pColumn5.add(lblTotalContract);
              pColumn5.add(txtTotalContract);
              pColumn5.add(new JLabel(" "));
              pColumn5.add(new JLabel(" "));
              pColumn5.add(lblCumNetPay);
              pColumn5.add(txtCumNetPay);
              pColumn5.add(new JLabel(" "));
              pColumn5.add(new JLabel(" "));
              pColumn5.add(lblAvgNetPay);
              pColumn5.add(txtAvgNetPay);
              pColumn5.setBackground(manilla);
              lblTotalContract.setForeground(Color.black);
              txtTotalContract.setForeground(Color.black);
              lblCumNetPay.setForeground(Color.black);
              txtCumNetPay.setForeground(Color.black);
              lblAvgNetPay.setForeground(Color.black);
              txtAvgNetPay.setForeground(Color.black);
              pBasicPayGridRight.add(pColumn1);
              pBasicPayGridRight.add(pColumn2);
              pBasicPayGridRight.add(pColumn3);
              pBasicPayGridRight.add(pColumn4);
              pBasicPayGridRight.add(pColumn5);
              pBasicPayGridRight.setBackground(manilla);
          * Sets up the trend report main panel that holds the graph and the bottom trend report
         public void trendReportMain()//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
              //pTrendReportMain.add(trendReport);// changed pTrendReport to trendReport
              pTrendRepMain.add(trendReport);//changed pTrendRepMain to trendReport
              pTrendRepMain.add(pTrendBot);
              trendReportTotalsPanel();
         public void trendReportTotalsPanel()
              JPanel pTrendLeftRight = new JPanel(new FlowLayout(FlowLayout.CENTER,10,5));
                pTrendBot.add(pTrendLeftRight);
                pTrendBot.setBackground(manilla);
                pTrendLeftRight.add(pTrendGridLeft);
                pTrendLeftRight.add(pTrendGridRight);
                pTrendLeftRight.setBackground(manilla);
                trendReportLeft();
                trendReportRight();
         public void trendReportLeft()
              JPanel pColumn1 = new JPanel(new GridLayout(10,1));
              JLabel lblTotalEmployees = new JLabel("Recent Pay Period Worked");
              JLabel lblCumulativePay = new JLabel("Cumulative Pay Info");
              JLabel lblAveragePay = new JLabel("Average Pay Info");
              JLabel lblShim1 = new JLabel("X");
              JLabel lblShim2 = new JLabel("X");
              JLabel lblShim3 = new JLabel("X");
              lblShim1.setForeground(manilla);
              lblShim2.setForeground(manilla);
              lblShim3.setForeground(manilla);
              pColumn1.add(lblTotalEmployees);
              pColumn1.add(lblShim1);
              pColumn1.add(new JLabel(" "));
              pColumn1.add(new JLabel(" "));
              pColumn1.add(lblCumulativePay);
              pColumn1.add(lblShim2);
              pColumn1.add(new JLabel(" "));
              pColumn1.add(new JLabel(" "));
              pColumn1.add(lblAveragePay);
              pColumn1.add(lblShim3);
              pColumn1.setBackground(manilla);
              lblTotalEmployees.setForeground(Color.black);
              lblCumulativePay.setForeground(Color.black);
              lblAveragePay.setForeground(Color.black);
              pTrendGridLeft.add(pColumn1);
              pTrendGridLeft.setBackground(manilla);
         public void trendReportRight()
              JPanel pColumn1 = new JPanel(new GridLayout(10,1));
              JPanel pColumn2 = new JPanel(new GridLayout(10,1));
              JPanel pColumn3 = new JPanel(new GridLayout(10,1));
              JPanel pColumn4 = new JPanel(new GridLayout(10,1));
              JPanel pColumn5 = new JPanel(new GridLayout(10,1));
                JLabel lblTotalEmployees = new JLabel("Employees");
                JLabel lblTotalSalaried = new JLabel("Salaried");
                JLabel lblTotalHourly = new JLabel("Hourly");
                JLabel lblTotalTemporary = new JLabel("Temporary");
                JLabel lblTotalContract = new JLabel("Contract");
                JLabel lblCumHourlyRate = new JLabel("Pay Rate");
                JLabel lblCumHoursWorked = new JLabel("Hours Worked");
                JLabel lblCumGrossPay = new JLabel("Gross Pay");
                JLabel lblCumTax = new JLabel("Flat Tax 15%");
                JLabel lblCumNetPay = new JLabel("Net Pay");
                JLabel lblAvgHourlyRate = new JLabel("Pay Rate");
                JLabel lblAvgHoursWorked = new JLabel("Hours Worked");
                JLabel lblAvgGrossPay = new JLabel("Gross Pay");
                JLabel lblAvgTax = new JLabel("Flat Tax 15%");
                JLabel lblAvgNetPay = new JLabel("Net Pay");
              pColumn1.add(lblTotalEmployees);
              pColumn1.add(txtTrendTotalEmployees);     //txtTrendTotalEmployees
              pColumn1.add(new JLabel                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            &n

    This class declaration won't do for loading into a JTabbedPane
    public class TrendReport extends JFrame implements ActionListener {Try this in it's place
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TrendRx {
      public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        TrendReport trendReport = new TrendReport();
        f.getContentPane().add(trendReport);
        f.setSize(500,300);
        f.setLocation(100,100);
        f.setVisible(true);
    class TrendReport extends JPanel implements ActionListener {
      int width;
      int height;
      JButton button;
      int []bar = new int[4];
      float []flote = {1395,1296,1402,1522};
      String []valuesInput = {"1395","1296","1402","1522"};
      String str = "", title="Title goes here";
      String []barLabels = {
        "pp01, Oct. 2003","pp02, Oct. 2003","pp01, Nov. 2003","pp02, Nov. 2003"
      String []percent = {"","","",""};
      JLabel []JLab = new JLabel[4];
      JTextField titletxt;
      JTextField []Text = new JTextField[5];
      JTextField []labeltxt = new JTextField[5];
      boolean pieChart;
      public TrendReport() {
        setOpaque(false);
        setLayout(new FlowLayout() );
        button = new JButton("Bar TrendReport");
        button.addActionListener(this);
    //    for (int k=0; k<4; k++){
    //      str = Integer.toString(k+1);
        add(button);
      public void paintComponent(Graphics g) {
        width = getWidth();
        height = getHeight();
        Graphics2D g2 = (Graphics2D)g;                    
        g2.setColor(new Color(223,222,224));
        g2.fillRect(0,0,width,height);
        g2.setColor(Color.orange);
        if(pieChart) {
          g2.fillArc(getW(30), getH(130), getW(220), getH(220), 90, -bar[0]);
          g2.fillRect(getW(270), getH(170), getW(30), getH(20));
        else
          g2.fillRect(getW(30), getH(150), getW(bar[0]), getH(30));
        g2.setColor(Color.green);
        if(pieChart) {
          g2.fillArc(getW(30), getH(130), getW(220), getH(220), 90-bar[0], -bar[1]);
          g2.fillRect(getW(270), getH(210), getW(30), getH(20));
        else
          g2.fillRect(getW(30), getH(190), getW(bar[1]), getH(30));
        g2.setColor(Color.red);
        if(pieChart) {
          g2.fillArc(getW(30), getH(130), getW(220), getH(220),
                     90-(bar[0]+bar[1]), -bar[2]);
          g2.fillRect(getW(270), getH(250), getW(30), getH(20));
        else
          g2.fillRect(getW(30), getH(230), getW(bar[2]), getH(30));
        g2.setColor(Color.blue);
        if(pieChart) {
          g2.fillArc(getW(30), getH(130), getW(220), getH(220),
                     90-(bar[0]+bar[1]+bar[2]), -bar[3]);
          g2.fillRect(getW(270), getH(290), getW(30), getH(20));
        else
          g2.fillRect(getW(30), getH(270), getW(bar[3]), getH(30));
        g2.setColor(Color.black);
        g2.setFont(new Font("Arial", Font.BOLD, 18));
        if(pieChart)
          g2.drawString(title, getW(220), getH(142));
        else
          g2.drawString(title, getW(50), getH(132));
        g2.setFont(new Font("Arial", Font.PLAIN,16));
        int temp=0;
        if(pieChart)
          temp = 185;
        else
          temp = 172;
        for(int j=0; j <4; j++) {
          if(pieChart)
            g2.drawString("$"+valuesInput[j]+" "+barLabels[j]+percent[j],
                          getW(305), getH(temp));//XXXXXXXXXXXXXXX
          else
            g2.drawString("$"+valuesInput[j]+" "+barLabels[j]+percent[j],
                          getW(bar[j]+40), getH(temp));
          temp += 40;
        if(!pieChart){
          g2.drawLine(getW(30), getH(130), getW(30), getH(300));
          g2.drawLine(getW(30), getH(300), getW(430), getH(300));               
          g2.setFont(new Font("Arial", Font.PLAIN,12));
        super.paintComponent(g2);
      private int getW(int dx) {
        return (dx * width) / 550;
      private int getH(int dy) {
        return (dy * height) / 400;
      public void actionPerformed(ActionEvent e) {
        String command = e.getActionCommand();
        if(command.equals("Bar TrendReport")){
          button.setText("Pie Chart");
          pieChart=false;
          try {
            int temp =0;
            java.text.DecimalFormat df = new java.text.DecimalFormat("#0.#");
            for (int j=0; j<4; j++){
              //flote[j] = Float.parseFloat(Text[j].getText());//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
              temp += (int)((flote[j]) +0.5);
            for (int k=0; k<4; k++){
              bar[k] = (int)(((flote[k]/temp) * 360)+0.5);
              //barLabels[k] = labeltxt[k].getText();XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
              flote[k] = (flote[k]/temp) *100;
              percent[k] = ": "+df.format(flote[k])+"%";
          catch(Exception message){
            title = "Oops! Complete all fields, enter numbers only";
        if(command.equals("Pie Chart")){
          button.setText("Bar TrendReport");
          pieChart=true;
        repaint();
    }

  • ScrollBars not showing up for the JPanel [urgent]

    Hi,
    I have a frame in which i have two nested split panes i.e one horizontal splitpane and in that i am having one more split pane on the right side and a JTree on the left side.In the second split pane (which is a vertical split) ,as a top component , i am setting a JScrollPane in which i am trying to display a JPanel which is having a lot of swing components in it.I want to see the scroll bars for this panel so that i can see all the components.Do i have to implement Scrollable interface for this panel to scroll in the ScrollPane.I don't know how to implement Scrollable interface.Can some body help me in resolving this?This is some what urgent.Any help will be highly appreciated.
    Thanks in advance.
    Ashok

    Thank you all for your replies.I added the scroll bar policy.The scroll bars are showing up but the components inside the Panel are not moving.I want the components to move when i am scrolling.Here is my code.In the code SeriesDescPanel, SeriesDescMapPanel are sub classes of JPanel.I am using null layout to add the components to these panels.
    public class MainWindow extends JFrame implements TreeExpansionListener
    public MainWindow()
    throws RemoteException
    // This code is automatically generated by Visual Cafe when you add
              // components to the visual environment. It instantiates and initializes
              // the components. To modify the code, only use code syntax that matches
              // what Visual Cafe can generate, or Visual Cafe may be unable to back
              // parse your Java file into its visual environment.
              //{{INIT_CONTROLS
              setJMenuBar(menuBar);
              setTitle("Series Maintenance");
              getContentPane().setLayout(new BorderLayout(0,0));
              setSize(667,478);
              setVisible(false);
              JSplitPane1.setDividerSize(1);
              JSplitPane1.setOneTouchExpandable(true);
              getContentPane().add(BorderLayout.CENTER, JSplitPane1);
              seriesMenu.setText("Series");
              seriesMenu.setActionCommand("Series");
              menuBar.add(seriesMenu);
              newSeriesGroupMenuItem.setText("New Series Group");
              newSeriesGroupMenuItem.setActionCommand("New Series Group");
              seriesMenu.add(newSeriesGroupMenuItem);
              newSeriesMenuItem.setText("New Series");
              newSeriesMenuItem.setActionCommand("New Series");
              seriesMenu.add(newSeriesMenuItem);
              seriesMenu.add(JSeparator1);
              serachMenuItem.setText("Search");
              serachMenuItem.setActionCommand("Search");
              seriesMenu.add(serachMenuItem);
              seriesMenu.add(JSeparator2);
              saveMenuItem.setText("Save");
              saveMenuItem.setActionCommand("Save");
              seriesMenu.add(saveMenuItem);
              seriesMenu.add(JSeparator3);
              exitMenuItem.setText("Exit");
              exitMenuItem.setActionCommand("Exit");
              seriesMenu.add(exitMenuItem);
              adminMenu.setText("Administration");
              adminMenu.setActionCommand("Administration");
              menuBar.add(adminMenu);
              bulkLoadMenuItem.setText("Bulk Load");
              bulkLoadMenuItem.setActionCommand("Bulk Load");
              adminMenu.add(bulkLoadMenuItem);
              drsMenuItem.setText("DRS override");
              drsMenuItem.setActionCommand("DRS override");
              adminMenu.add(drsMenuItem);
              helpMenu.setText("Help");
              helpMenu.setActionCommand("Help");
              menuBar.add(helpMenu);
              tutorialMenuItem.setText("Tutorial");
              tutorialMenuItem.setActionCommand("Tutorial");
              helpMenu.add(tutorialMenuItem);
              bulkLoadFormatMenuItem.setText("Bulk Load Format");
              bulkLoadFormatMenuItem.setActionCommand("Bulk Load Format");
              helpMenu.add(bulkLoadFormatMenuItem);
              aboutMenuItem.setText("About");
              aboutMenuItem.setActionCommand("About");
              helpMenu.add(aboutMenuItem);
    JSplitPane2 = new javax.swing.JSplitPane();
    upperPanel = new SeriesDescPanel();
    JScrollPane2 = new javax.swing.JScrollPane(upperPanel,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    JScrollPane3 = new javax.swing.JScrollPane();
    JSplitPane2.setOrientation(0);
    JSplitPane2.setDividerSize(1);
    JSplitPane2.setOneTouchExpandable(true);
    JSplitPane1.setRightComponent(JSplitPane2);
    JSplitPane1.setLeftComponent(viewPane);
    viewPane.add(alphabeticPane);
    viewPane.add(searchDataPane);
    viewPane.setTitleAt(0,"All");
              viewPane.setTitleAt(1,"search");
    //JScrollPane1.setMinimumSize(new Dimension(126, 478));
    JSplitPane2.setTopComponent(JScrollPane2);
    //JScrollPane2.setMinimumSize(new Dimension(426, 409));
    JSplitPane2.setBottomComponent(JScrollPane3);
    lowerPanel = new SeriesDescMapPanel();
    seriesTreeModel = new SeriesTreeModel(SeriesMaintenanceUI.getSeriesGroupInfo());
    tickersTree.setModel(seriesTreeModel);
    alphabeticPane.getViewport().setView(tickersTree);
    //JScrollPane2.getViewport().setView(upperPanel);
    //JScrollPane2.setViewportView(upperPanel);
    //upperPanel.scrollRectToVisible(new Rectangle(upperPanel.getWidth(),
    //upperPanel.getHeight(),1,1));
    JScrollPane3.getViewport().setView(lowerPanel);
    //JSplitPane2.setPreferredSize(new Dimension(426,200));
    SeriesDescPanel upperPanel;
    SeriesDescMapPanel lowerPanel;
    SeriesTreeModel seriesTreeModel;
    SeriesTreeModel searchTreeModel;
    javax.swing.JSplitPane JSplitPane2;
    javax.swing.JScrollPane JScrollPane2;
    javax.swing.JScrollPane JScrollPane3;
    javax.swing.JTree tickersTree = new javax.swing.JTree();
    javax.swing.JTree searchTree = new javax.swing.JTree();
    javax.swing.JScrollPane alphabeticPane = new javax.swing.JScrollPane();
    javax.swing.JTabbedPane viewPane = new JTabbedPane(SwingConstants.BOTTOM);
    javax.swing.JScrollPane searchDataPane = new javax.swing.JScrollPane();
    //{{DECLARE_CONTROLS
         javax.swing.JSplitPane JSplitPane1 = new javax.swing.JSplitPane();
         javax.swing.JMenuBar menuBar = new javax.swing.JMenuBar();
         javax.swing.JMenu seriesMenu = new javax.swing.JMenu();
         javax.swing.JMenuItem newSeriesGroupMenuItem = new javax.swing.JMenuItem();
         javax.swing.JMenuItem newSeriesMenuItem = new javax.swing.JMenuItem();
         javax.swing.JSeparator JSeparator1 = new javax.swing.JSeparator();
         javax.swing.JMenuItem serachMenuItem = new javax.swing.JMenuItem();
         javax.swing.JSeparator JSeparator2 = new javax.swing.JSeparator();
         javax.swing.JMenuItem saveMenuItem = new javax.swing.JMenuItem();
         javax.swing.JSeparator JSeparator3 = new javax.swing.JSeparator();
         javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
         javax.swing.JMenu adminMenu = new javax.swing.JMenu();
         javax.swing.JMenuItem bulkLoadMenuItem = new javax.swing.JMenuItem();
         javax.swing.JMenuItem drsMenuItem = new javax.swing.JMenuItem();
         javax.swing.JMenu helpMenu = new javax.swing.JMenu();
         javax.swing.JMenuItem tutorialMenuItem = new javax.swing.JMenuItem();
         javax.swing.JMenuItem bulkLoadFormatMenuItem = new javax.swing.JMenuItem();
         javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
    Pl. help me in resolving this.
    Ashok

  • Painting in JPanels

    Hey guys, thanks for the help with the last question. Heres another for the same program!
    So this program generates a JFrame which is populated with JPanel's in a gridLayout() format. The grid is supposed to represent a maze which is navigated by clicking on the appropriate panels.
    The first problem I'm having is trying to get the starting square, the current square and the squares that have previously stepped on to change color. Also the current square should show a circle to indicate where you are.
    Instead of doing that the squares are just showing random graphics on them due to an arbitrary line of code i put in:
    Graphics g = getGraphics();If i take that out then nothing changes color/graphics.
    The second problem I'm having is when i load a new maze (or the same one) instead of replacing the displayed one it tries to squish them both in. Yet when i print out all the values like the number of columns in the gridLayout it they are all correct. I'm hoping this is just a display error and will be fixed with the first problem.
    The Maze.java class brings everything together and calls the Walls.java class which creates and adds the JPanel's which are GridPanel.java objects. The Move.java and Maze.java alters the GridPanel's to be current or not... Good Luck =) and thanks heaps as always! YOU GUYS ARE LIFESAVERS!!!
    //Ass2.java
    public class Assign2
         public static void main(String[] args)
              Maze theMaze = new Maze();
    //Maze.java
    import java.io.*;
    import java.util.Vector;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Maze extends JFrame
         Vector<String> data = new Vector<String>();
         GridPanel[][] panel;
         private int[] endPoints = new int[4];
         private int[] size = new int[2];
         private int moveNum;
         private int theSize;
         private int cX;
         private int cY;
         private int pX;
         private int pY;
         public Maze()
              MazeApp s = new MazeApp(this);
              moveNum = 0;
              File f = new File("maze.txt");
              readMaze(f);
         public void readMaze(File fName)
              File fileName = fName;
              Read r = new Read();
              data.clear();
              size = r.readFile(endPoints, data, fileName);
              theSize = (size[1] * size[0]);
              cX = endPoints[0];
              cY = endPoints[1];
              GridLayout layout = new GridLayout();
              layout.setRows(size[1]);
              layout.setColumns(size[0]);
              this.setLayout(layout);
              System.out.println(data.size());
              makeMaze();
         public void makeMaze()
              panel = new GridPanel [size[1]][size[0]];
              Walls w = new Walls(data, size, this);
              w.drawWalls(panel);
              panel[endPoints[1]][endPoints[0]].setStart();
              panel[endPoints[3]][endPoints[2]].setEnd();
              this.setSize(size[0]*100, size[1]*100);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setVisible(true);
         public void checkMove(Point clicked, int w, int h, int wall)
              pY = (int)(clicked.getX())/w;
              pX = (int)(clicked.getY())/h;
              Move m = new Move(cX, cY, pX, pY, w, h, wall);
              if(m.check() == 1) //MOVE NORTH
                   if((panel[cX-1][cY].checkWall() != 2) && (panel[cX-1][cY].checkWall() != 3))
                   {setCurrent();}else{JOptionPane.showMessageDialog(this, "Invalid Move! Cannot move through walls!");}
              if(m.check() == 2) //MOVE SOUTH
                   if((panel[cX][cY].checkWall() != 2) && (panel[cX][cY].checkWall() != 3))
                   {setCurrent();}else{JOptionPane.showMessageDialog(this, "Invalid Move! Cannot move through walls!");}
              if(m.check() == 3) //MOVE WEST
                   if((panel[pX][pY].checkWall() != 1) && (panel[pX][pY].checkWall() != 3))
                   {setCurrent();}else{JOptionPane.showMessageDialog(this, "Invalid Move! Cannot move through walls!");}
              if(m.check() == 4) //MOVE EAST
                   if((panel[cX][cY].checkWall() != 1) && (panel[cX][cY].checkWall() != 3))
                   {setCurrent();}else{JOptionPane.showMessageDialog(this, "Invalid Move! Cannot move through walls!");}
              if(m.check() == 0 )
              {JOptionPane.showMessageDialog(this, "Invalid Move! Invalid square selected!\nPlease choose an adjacent square.");}
         public void setCurrent()
              panel[cX][cY].setUsed();
              panel[pX][pY].setCurrent();
              cX = pX;
              cY = pY;
              moveNum++;
              if(cY == endPoints[2] && cX == endPoints[3])
              {JOptionPane.showMessageDialog(this, "Congratulations!\nYou finished in" + moveNum + "moves!");}
    // MazeApp.java
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    public class MazeApp extends JFrame
           private Maze theMaze;
           public MazeApp(Maze m)
                   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   theMaze = m;
                   // create the menu bar to hold the menus...
                   JMenuBar menuBar = new JMenuBar();
                   // create the menus to hold the menu items...
                   JMenu menuFile = new JMenu("File");
                   JMenu menuOptions = new JMenu("Options");
                   JMenu menuHelp = new JMenu("Help");
                   // create file menu options:
                   JMenuItem itemLoad = new JMenuItem("Load");
                   JMenuItem itemSaveAs = new JMenuItem("Save As...");
                   JRadioButtonMenuItem itemModePlay = new JRadioButtonMenuItem("Play");
                   JRadioButtonMenuItem itemModeEdit = new JRadioButtonMenuItem("Edit");
                   JMenuItem itemExit = new JMenuItem("Exit");
                   //create options menu:
                   JRadioButtonMenuItem itemNoRats = new JRadioButtonMenuItem("No Rats");
                   JRadioButtonMenuItem itemOneRat = new JRadioButtonMenuItem("One Rat");
                   JRadioButtonMenuItem itemTwoRats = new JRadioButtonMenuItem("Two Rats");
                   //create help option:
                   JMenuItem itemHelp = new JMenuItem("Help");
                   JMenuItem itemAbout = new JMenuItem("About");
                   //set default options:
                   itemModePlay.setSelected(true);                    
                   itemNoRats.setSelected(true);
                   // add File options:
                   menuFile.add(itemLoad);
                   menuFile.add(itemSaveAs);
                   menuFile.addSeparator();
                   menuFile.add(itemModePlay);
                   menuFile.add(itemModeEdit);
                   menuFile.addSeparator();
                   menuFile.add(itemExit);
                   //add Options:
                   menuOptions.add(itemNoRats);
                   menuOptions.add(itemOneRat);
                   menuOptions.add(itemTwoRats);
                   //add Help options:
                   menuHelp.add(itemHelp);
                   menuHelp.add(itemAbout);
                   // add the menu to the menu bar...
                   menuBar.add(menuFile);
                   menuBar.add(menuOptions);
                   menuBar.add(menuHelp);
                   // finally add the menu bar to the app...
                   m.setJMenuBar(menuBar);
                   //listeners
                   itemExit.addActionListener(
                           new ActionListener()
                                   public void actionPerformed( ActionEvent event )
                                           System.exit( 0 );
                itemLoad.addActionListener(
                   new ActionListener()
                        public void actionPerformed( ActionEvent event )
                             final JFileChooser fc = new JFileChooser();
                             int returnVal = fc.showOpenDialog(MazeApp.this);
                          File fileName = fc.getSelectedFile();
                             if(fileName.exists())
                                  theMaze.readMaze(fileName);
                             else
                                  System.out.println("404. File not found");
                   itemAbout.addActionListener(
                           new ActionListener()
                                   public void actionPerformed( ActionEvent event )
                                           //do stuff
                                           JOptionPane.showMessageDialog(MazeApp.this, "Author: Pat Purcell\[email protected]", "About", JOptionPane.ERROR_MESSAGE);
    //Read.java
    import java.io.*;
    import java.util.Vector;
    public class Read
         private BufferedReader input;
         private String line;
         private String fileName;
         private String[] temp;
         private int[] size = new int[2];
         public int[] readFile(int[] endPoints, Vector<String> data, File fileName)
              try
                   data.clear();
                   FileReader fr = new FileReader(fileName);
                   input = new BufferedReader(fr);
                   line = input.readLine();
                   temp = line.split("\\s");
                   for(int i =0;i<2;i++)
                   {size[i] = Integer.parseInt(temp);}
                   line = input.readLine();
                   temp = line.split("\\s");
                   for(int i =0;i<4;i++)
                   {endPoints[i] = Integer.parseInt(temp[i]);}
                   line = input.readLine();
                   while (line != null)
                        String[] temp = line.split("\\s");
                        for(int i=0;i<size[0];i++)
                             data.addElement(temp[i]);
                        line = input.readLine();
                   input.close();
              catch (IOException e)
                   System.err.println(e);
              return size;
    }//Walls.java
    import java.util.Vector;
    import java.awt.GridLayout;
    import javax.swing.*;
    public class Walls extends JFrame
         private Vector<String> data = new Vector<String>();
         private int size;
         private Maze bm;
         private int row;
         private int column;
         public Walls(Vector<String> theData, int[] theSize, Maze m)
              data = theData;
              row = theSize[1];
              column = theSize[0];
              size = row*column;
              bm = m;
         public boolean testEast(int position)
              boolean exists;
              String temp = data.get(position);
              int eastData = ((int)temp.charAt(0) - (int)'0');
              if(1 == (eastData))
                   return true;
              return false;
         public boolean testSouth(int position)
              boolean exists;
              String temp = data.get(position);
              int southData = ((int)temp.charAt(1) - (int)'0');
              if(1 == (southData))
                   return true;
              return false;
         public boolean testBoth(int position)
              boolean exists;
              if((testEast(position) && testSouth(position)) == true)
                   return true;
              return false;
         public void drawWalls(GridPanel panel[][])
              int i = 0;
              for(int y=0;y<row;y++)
                   for(int x=0;x<column;x++, i++)
                   if (testBoth(i) == true)
                   {     GridPanel temp = new GridPanel(3, bm);
                        panel[y][x] = temp;
                                  bm.add(temp);}
                   else{
                        if (testEast(i) == true)
                        {     GridPanel temp = new GridPanel(1, bm);
                             panel[y][x] = temp;
                                  bm.add(temp);}
                        else{
                             if (testSouth(i) == true)
                             {     GridPanel temp = new GridPanel(2, bm);
                                  panel[y][x] = temp;
                                  bm.add(temp);}
                             else{
                                  GridPanel temp = new GridPanel(0, bm);
                                  panel[y][x] = temp;
                                  bm.add(temp);}
    }//GridPanel.java
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    public class GridPanel extends JPanel implements MouseListener
    private int wall;
    private Maze bm;
    private Ellipse2D.Double circle = new Ellipse2D.Double();
    private Graphics gr;
    boolean current = false;
    boolean start = false;
    boolean finish = false;
    public GridPanel(int theWall, Maze m)
         wall = theWall;
         this.addMouseListener(this);
         bm = m;
         public void paintComponent(Graphics g)
              Graphics2D g2 = (Graphics2D)g;
              g2.setStroke(new BasicStroke(1));
              g2.draw(new Line2D.Double(this.getWidth()-1, 0, this.getWidth()-1, this.getHeight()-1));
              g2.draw(new Line2D.Double(0, this.getHeight()-1, this.getWidth()-1, this.getHeight()-1));
              g2.setStroke(new BasicStroke(4));
              if(wall == 0) //NO WALL
              if(wall == 1) //EAST WALL
                   g2.draw(new Line2D.Double(this.getWidth()-1, 0, this.getWidth()-1, this.getHeight()-1));
              if(wall == 2) //SOUTH WALL
                   g2.draw(new Line2D.Double(0, this.getHeight()-1, this.getWidth()-1, this.getHeight()-1));
              if(wall == 3) //BOTH WALLS
                   g2.draw(new Line2D.Double(0, this.getHeight()-1, this.getWidth()-1, this.getHeight()-1));
                   g2.draw(new Line2D.Double(this.getWidth()-1, 0, this.getWidth()-1, this.getHeight()-1));
              if(current == true)
                   setBackground(SystemColor.green);
                   circle = new Ellipse2D.Double();
                   circle.x = 0;
                   circle.y = 0;
                   circle.height = this.getHeight()-1; // -1 so it fits inside the panel.
                   circle.width = this.getWidth()-1;
                   g2.draw(circle);
                   repaint();
              if(start == true)
              {     setBackground(SystemColor.green);
                   g2.drawString("S", this.getWidth()/2, this.getHeight()/2);}
              if(finish == true)
              {     setBackground(SystemColor.green);
                   g2.drawString("F", this.getWidth()/2, this.getHeight()/2);}
         public int checkWall()
              return wall;
         public void setCurrent()
              Graphics g = getGraphics();
              repaint();
         public void setUsed()
              current = false;
              repaint();
         public void setStart()
              start = true;
              repaint();
         public void setEnd()
              finish = true;
              repaint();
         public void mouseClicked(MouseEvent e){bm.checkMove(this.getLocation(), this.getWidth(), this.getHeight(), wall);}
         public void mouseReleased (MouseEvent e) {}
         public void mouseEntered (MouseEvent e) {}
         public void mouseExited(MouseEvent e) {}
         public void mousePressed(MouseEvent e) {}
    }//Move.java
    import java.awt.*;
    public class Move
         private int pX;
         private int pY;
         private int cX;
         private int cY;
         private int w;
         private int h;
         private int wall;
         public Move(int x1, int y1, int x2, int y2, int theWidth, int theHeight, int wallCheck)
              pX = x2;
              pY = y2;
              cX = x1;
              cY = y1;
              w = theWidth;
              h = theHeight;
         public int check()
              //System.out.println(cX + " " + (pX + 1));
              if((cX == (pX + 1)) && (cY == pY)) //MOVE NORTH
              {return 1;}
              //System.out.println(cX + " " + (pX - 1));
              if((cX == (pX - 1)) && (cY == pY)) //MOVE SOUTH
              {return 2;}
              //System.out.println(cY + " " + (pY + 1));
              if((cY == (pY + 1)) && (cX == pX))//MOVE WEST
              {return 3;}
              //System.out.println(cY + " " + (pY - 1));
              if((cY == (pY - 1)) && (cX == pX))//MOVE EAST
              {return 4;}
              return 0;
    }This is the file the maze is read out of: Maze.txt6 5
    0 0 3 2
    10 00 01 01 01 10
    10 10 00 01 10 10
    10 10 01 11 10 10
    10 01 01 01 11 10
    01 01 01 01 01 11                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    -> Second proplem that still remains is the circle stays after you leave the square...
    Thats why I suggested you use a Border and not do custom painting. There is no such method as remove(...). You need to repaint the entire panel. If you use a Border you just use setBorder(...) to whatever. So you have two different Borders. One for when the component has focus and one for when the component doesn't.
    -> but the same two problems remain.
    Well, I don't know whats wrong and I am not about to debug your program since I have no idea what it is doing. So create a SSCCE to post.
    see http://homepage1.nifty.com/algafield/sscce.html,
    Basically all you need to do is create a JFrame. Create a "main" panel with a flow layout and add it to the content pane. Then create 3 or 4 panels with a default Border on a black line and add the panels to the "main" panel. Then add you MouseListeners and FocusListeners to the panels. The whole program should be 30 lines of code or so. Understand how that program works and then apply the same concepts to you real program.
    The point is when you attempt to do something new that you don't understand write a simple program so you can prove to yourself that it works. If you can't get it working then you have a simple SSCCE to post and then maybe someone will look at it.

  • JMenu's

    I have a components in my program that are used by both a JMenu and a JPopupMenu. The problem is that if I tell the my application to add the components to the JMenu and then to the JPopupMenu it won't appear in the JMenu, As if it wasn't added. But it appears in the JMenu! What went wrong?

    I suspect this is the same as most Swing things...
    If you try to add the same JPanel into West and East of a BorderLayout the JPanel will only appear in the last place you added it.
    I suspect you need to duplicate the JMenuItems and add 1 set to the JMenu & one the JPopupMenu... you should be able to attach the same listener to the items though to save some code duplication.

Maybe you are looking for

  • Unable to install itunes 10.01

    When I try to install itunes, it get halfway done, but then an error message comes up saying- "The feature you are trying to use is on a network resource that is unavailable. Click OK to try again, or an alternate path to a folder containing the inst

  • N: 1 relationships in Value Mapping 3.0

    Hi, in our Value Mapping we need to process n:1 relationships between values. E.g. 2 different codes for reason-for-rejection in the sending system need to be mapped to 1 value in the receiving system. As we see now, and this is also mentioned somewh

  • No Listener service after installing Oracle 10g 2

    Hi, I have finished installing Oracle 10g 2 on a windows 2003 server. But no Listener windows service is not created. Any explanation ? Should I create the manually , How ? Many thanks.

  • Editing files in my catalog and then moving them back. Help.

    I want to take a folder of images in the LR catalog on my desktop with me while travelling so that I can edit them on my laptop but, the question I have is, if I export them as a catalog to a portable drive, how do I put them back in the catalog on m

  • How come my autocorrect turns every 2 letter word to "on" ?

    So if I type the following things into my phone it gets autocorrected to on : it or Im no Are a few that I can think of.. is there anyway for me to erase this from my phones auto correct memory. I've tried setting up shortcut words too and that does