Consequences of having a panel in a JFrame?

Hi,
Can we embed an AWT panel in a JFrame? What are the consequences of doing that? I am trying to do this and am facing problems trying to display the panel in the JFrame....but if i either minimize the JFrame or move it around causing it to repaint...the panel becomes visible....does anyone know how i can solve the problem?
Thanks,
Ravi.

Mixing heavyweight (AWT) and lightweight (Swing) components is not recommended. For more information, see the bottom of the following Tutorial page: http://java.sun.com/docs/books/tutorial/uiswing/start/swingIntro.html

Similar Messages

  • Problem with Paining in a Panel in a JFrame.

    So I can paint directly on a JFrame, and I can paint on a class that extends Panel, and put the Panel on a JFrame. But if I try to Repaint the Panel it won't show on the JFrame. Do I have to do anything to the JFrame to show the changes to the objects inside as well?

    I'm not sure if you've done this, but don't change the paint method when using Swing components, use paintComponent instead. By default, the JFrame will paint its children. Just remember whenever overriding any of the paintComponent methods to call super.paintComponent(g) first.

  • How can I add JScrollpane to one of the panels of a JFrame????

    I want to generate a screen with one JFrame and two JPanels.one panel to the left of the Frame and another to the right.
    I want to add a Jscrollpane to left panel,to which i am adding images so that they can be scrolled.How can I achieve this ???????????
    please reply me.............
    this is Basic Frame class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    public class BasicFrame
    private JFrame frame = null;
    private JPanel CanvasPanel = new JPanel();
    private JPanel libraryPanel = null;
    public static void main(String args[])
    new BasicFrame();
    public BasicFrame()
    frame = new JFrame( "Java3d Demo of VRML Loading ");
    frame.setSize( 800, 600 );
    frame.setLayout(new BorderLayout());
         frame.add(CanvasPanel,BorderLayout.EAST);
    frame.add(new LibraryPanel(),BorderLayout.WEST);
         frame.setMenuBar(createMenuBar());
    frame.setVisible( true );
         // kill the window on close
         frame.addWindowListener(new WindowAdapter()
         public void windowClosing(WindowEvent winEvent)
         System.exit(0);
    public MenuBar createMenuBar()
    MenuBar menubar = new MenuBar();
         Menu menu;
    Menu subMenu;
    MenuItem menuItem;
    menu = new Menu("File");
    menuItem = new MenuItem("New");
    menu.add(menuItem);
    //menuItem.addActionListener(this);
    menuItem = new MenuItem("Load");
    menu.add(menuItem);
    //menuItem.addActionListener(this);
    subMenu = new Menu("Save");
    menu.add(subMenu);
    menuItem = new MenuItem("VRML97");
    subMenu.add(menuItem);
    //menuItem.addActionListener(this);
    menuItem = new MenuItem("X3D");
    subMenu.add(menuItem);
    //menuItem.addActionListener(this);
    subMenu = new Menu("Print");
    menu.add(subMenu);
    menuItem = new MenuItem("VRML97");
    subMenu.add(menuItem);
    //menuItem.addActionListener(this);
    menuItem = new MenuItem("X3D");
    subMenu.add(menuItem);
    //menuItem.addActionListener(this);
    menuItem = new MenuItem("Quit");
    menu.add(menuItem);
    //menuItem.addActionListener(this);
    menubar.add(menu);
    menu = new Menu("View");
    menuItem = new MenuItem("Reset");
    menu.add(menuItem);
    menuItem.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    menubar.add(menu);
    return menubar;
    this is Library panel class.To this,I want to add Jscrollpane to scroll the images displayed in this panel.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    public class LibraryPanel extends JPanel
    private ArrayList<String> imageList = new ArrayList<String>();
    private ImageIcon imageIcon;
    private JLabel imageLabel[] = new JLabel[100];
    private String path = "small images";
    private JList list;
    LibraryPanel()
    setSize(400, 600);
    setBorder(BorderFactory.createLineBorder(Color.black));
    setLayout(new FlowLayout());
    JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);
    indexFiles();
    for(int imageNo=0;imageNo<imageList.size();imageNo++)
    try
    imageIcon = new ImageIcon(path + "/" + imageList.get(imageNo));
    imageLabel[imageNo] = new JLabel(imageIcon);
    //scrollPane.getViewport().
              add(imageLabel[imageNo]);
    catch (IllegalArgumentException illegalArgEx)
    illegalArgEx.printStackTrace();
         add(comboBox(),FlowLayout.CENTER);
    add(vbar,FlowLayout.CENTER);
    public JComboBox comboBox()
    String[] comboTypes = { "Sachin", "YuvRaj", "Ganguly", "Dravid", "Sehwag", "Dhoni" };
         // Create the combo box, and set 2nd item as Default
         JComboBox comboTypesList = new JComboBox(comboTypes);
         comboTypesList.setSelectedIndex(0);
         return comboTypesList;
    public void indexFiles()
    File dir = new File(path);
    String[] children = dir.list();
    if (children == null)
    System.err.println("Error: The directory doesn't exists!");
    System.exit(1);
    else
    imageList.ensureCapacity(children.length);
    for (int i = 0; i < children.length; i++)
    if(children.endsWith(".jpg"))
    imageList.add(children[i]);
    please reply me

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    public class BasicFrame
        private JFrame frame = null;
        private JPanel CanvasPanel = new JPanel();
        private JPanel libraryPanel = null;
        public static void main(String args[])
            new BasicFrame(); 
        public BasicFrame()
            frame = new JFrame( "Java3d Demo of VRML Loading ");
            frame.setSize( 800, 600 );
            frame.setLayout(new BorderLayout());
         frame.add(CanvasPanel,BorderLayout.EAST);
            frame.add(new LibraryPanel(),BorderLayout.WEST);
         frame.setMenuBar(createMenuBar());
            frame.setVisible( true );
         // kill the window on close
         frame.addWindowListener(new WindowAdapter()
             public void windowClosing(WindowEvent winEvent)
                 System.exit(0);
        public MenuBar createMenuBar()
            MenuBar menubar = new MenuBar();
         Menu menu;
            Menu subMenu;
            MenuItem menuItem;
            menu = new Menu("File");
            menuItem = new MenuItem("New");
            menu.add(menuItem);
            //menuItem.addActionListener(this);
            menuItem = new MenuItem("Load");
            menu.add(menuItem);
            //menuItem.addActionListener(this);
            subMenu = new Menu("Save");
            menu.add(subMenu);
            menuItem = new MenuItem("VRML97");
            subMenu.add(menuItem);
            //menuItem.addActionListener(this);
            menuItem = new MenuItem("X3D");
            subMenu.add(menuItem);
            //menuItem.addActionListener(this);
            subMenu = new Menu("Print");
            menu.add(subMenu);
            menuItem = new MenuItem("VRML97");
            subMenu.add(menuItem);
            //menuItem.addActionListener(this);
            menuItem = new MenuItem("X3D");
            subMenu.add(menuItem);
            //menuItem.addActionListener(this);
            menuItem = new MenuItem("Quit");
            menu.add(menuItem);
            //menuItem.addActionListener(this);
            menubar.add(menu);
            menu = new Menu("View");
            menuItem = new MenuItem("Reset");
            menu.add(menuItem);
            menuItem.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
            menubar.add(menu);
            return menubar;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    public class LibraryPanel extends JPanel
        private ArrayList<String> imageList = new ArrayList<String>();
        private ImageIcon imageIcon;
        private JLabel imageLabel[] = new JLabel[100];
        private String path = "small images";
        private JList list;
        LibraryPanel()
            setSize(400, 600);
            setBorder(BorderFactory.createLineBorder(Color.black));
            setLayout(new FlowLayout());
            JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);
            indexFiles();
            for(int imageNo=0;imageNo<imageList.size();imageNo++)
                try
                    imageIcon = new ImageIcon(path + "/" + imageList.get(imageNo));
                    imageLabel[imageNo] = new JLabel(imageIcon);
                    //scrollPane.getViewport().
              add(imageLabel[imageNo]);
                catch (IllegalArgumentException illegalArgEx)
                    illegalArgEx.printStackTrace();
         add(comboBox(),FlowLayout.CENTER);
            add(vbar,FlowLayout.CENTER);
        public JComboBox comboBox()
            String[] comboTypes = { "Sachin", "YuvRaj", "Ganguly", "Dravid", "Sehwag", "Dhoni" };
         // Create the combo box, and set 2nd item as Default
         JComboBox comboTypesList = new JComboBox(comboTypes);
         comboTypesList.setSelectedIndex(0);    
         return comboTypesList;
        public void indexFiles()
            File dir = new File(path);
            String[] children = dir.list();
            if (children == null)
                System.err.println("Error: The directory doesn't exists!");
                System.exit(1);
            else
                imageList.ensureCapacity(children.length);
                for (int i = 0; i < children.length; i++)
                    if(children.endsWith(".jpg"))
    imageList.add(children[i]);

  • Help needed in refreshing a panel in  a JFrame.

    I have some problem in refreshing a panel of a window.
    Here I am writting the sample code bellow.
    My program contains 2 classes, one is "Test" other is "Testwindow".
    class Test contains main(),displays the buttons reading from the string array obtained by listing a directory in my local file system through the panel p2 .If I click "Add" button in Test, class Testwindow's constructor is called & "Testwindow" is visible, which has a textfield. If you enter a string in the textfield, that string will be stored as a file in the same directory that the 1st window use. here I choose "C:\\temp" of my filesystem as the directory.
    My requirement is:
    when I enter a string in the textfield of Testwindow, then after clicking "Finish" button, that inputted string should be added to the panel p2 of 1st window(Test)during runtime.It means the panel p2 should be refreshed reading from the "C:\\temp" as soon as a new button is added to temp directory during runtime.
    If any of you have idea over this,please help sending me the updated version of the code given below.
    Regards.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class Test extends JFrame
    JPanel p1,p2;
    JButton b1,bdir[];
    File f;
    String s[];
    int n,nmax;
    public Test()
    super("Test");
    JPanel con=(JPanel)getContentPane();
    con.setLayout(new BorderLayout());
    addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e)
    System.exit(0);
    p1=new JPanel();
    p2=new JPanel();
    p2.setLayout(new GridLayout(nmax,1));
    b1=new JButton("Add");
    b1.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e)
    if(e.getActionCommand()=="Add")
    new Testwindow();
    p1.add(b1);
    f=new File("c:\\temp");
    s=f.list();
    n=s.length;
    nmax=n+20;
    bdir=new JButton[n];
    for(int i=0; i<n; i++)
    bdir=new JButton(s);
    bdir.setHorizontalAlignment(AbstractButton.LEADING);
    p2.add(bdir);
    int hor=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int ver=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp=new JScrollPane(p2,hor,ver);
    con.add(p1,"North");
    con.add(jsp,"Center");
    setSize(250,300);
    public static void main(String arg[])
    Test frame=new Test();
    frame.setVisible(true);
    class Testwindow extends JFrame implements ActionListener
    JPanel p1,p2,p3;
    JLabel l1;
    JTextField tf1;
    JButton b1,b2;
    String s1, sdir[];
    public Testwindow()
    setTitle("Testwindow");
    Container con=getContentPane();
    con.setLayout(new BorderLayout());
    p1=new JPanel();
    p1.setLayout(new GridLayout(1,2));
    p2=new JPanel();
    l1=new JLabel("Enter a string: ");
    tf1=new JTextField();
    b1=new JButton("Finish");
    b1.addActionListener(this);
    p1.add(l1);
    p1.add(tf1);
    p2.add(b1);
    con.add(p1,"North");
    con.add(p2, "South");
    setSize(300,150);
    show();
    public void actionPerformed(ActionEvent e)
    if(e.getActionCommand()=="Finish"){
    try{
    s1=tf1.getText();
    File id_name=new File("C:\\temp\\"+s1+".txt");
    FileOutputStream out=new FileOutputStream(id_name);
    out.close();
    catch(IOException x)
    System.out.println("Exception caught"+x);
    this.setVisible(false);

    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    public class test extends JFrame {
      JPanel p1, p2;
      JButton b1, bdir[];
      File f;
      String[] s;
      int n, nmax;
      public test() {
        super("Test");
        p1 = new JPanel();
        p2 = new JPanel();
        p2.setLayout(new GridLayout(nmax ,1));
        b1 = new JButton("Add");
        b1.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new Testwindow(test.this);
        p1.add(b1);
        f = new File("c:\\temp");
        s = f.list();
        n = s.length;
        nmax = n + 20;
        bdir = new JButton[n];
        for(int j = 0; j < n; j++) {
          bdir[j] = new JButton(s[j]);
          bdir[j].setHorizontalAlignment(AbstractButton.LEADING);
          p2.add(bdir[j]);
        JScrollPane jsp = new JScrollPane(p2);
        getContentPane().add(p1, "North");
        getContentPane().add(jsp, "Center");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(250,300);
        setLocation(100,100);
        setVisible(true);
       * Called by actionPerformed method in Testwindow
      public void addButton(String title) {
        JButton button = new JButton(title);
        button.setHorizontalAlignment(AbstractButton.LEADING);
        p2.add(button);
        p2.revalidate();
      public static void main(String[] args) {
        new test();
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    class Testwindow extends JFrame implements ActionListener {
      JPanel p1,p2,p3;
      JLabel label1;
      JTextField tf1;
      JButton b1,b2;
      String s1, sdir[];
      test client;
      public Testwindow(test client) {
        setTitle("Testwindow");
        this.client = client;
        p1=new JPanel();
        p1.setLayout(new GridLayout(1,2));
        p2=new JPanel();
        label1=new JLabel("Enter a string: ");
        tf1=new JTextField();
        b1=new JButton("Finish");
        b1.addActionListener(this);
        p1.add(label1);
        p1.add(tf1);
        p2.add(b1);
        getContentPane().add(p1, "North");
        getContentPane().add(p2, "South");
        setSize(300,150);
        setLocation(360,100);
        setVisible(true);
      public void actionPerformed(ActionEvent e) {
        JButton button = (JButton)e.getSource();
        if(button == b1) {
          try {
            s1=tf1.getText();
            File id_name=new File("C:\\temp\\"+s1+".txt");
            FileOutputStream out=new FileOutputStream(id_name);
            out.close();
          catch(IOException x) {
            System.out.println("Exception caught"+x);
          s1 = tf1.getText();
          client.addButton(s1);
          this.setVisible(false);
    }

  • Problem with displaying panel in a JFrame

    This application is supposed to display the actual month in a calendar with the current day in a red background.
    When running initially I get the frame with nothing in it, but if I resize it everything is displayed perfectly.
    I've played with the size of the JFrame and repaints methods but they are not woiking.
    I'll appreciate any information that you can give me
    thx
    Gustavo
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Assign2 extends JFrame
         private GregorianCalendar cal,temp;
         private int maxDay,minDay,firstDay,curDate;
         private String dayWeek[] = {"Sunday","Monday","Tuesday","Wednesday",
              "Thursday","Friday","Saturday"};
         private String month[] = {"January","February","March","April","May","June","July",
              "August","September","October","November","December"};
         JTextArea calDays[];
         private JPanel upper,lower,lowerDays,lowerGregorianCalendar;
         private JMenu file;
         private JMenuItem newDate,exit;
         private JMenuBar bar;
         private String banner;
         private JLabel dateBanner;
         public Assign2()
              // INITIALIZING CAL ( CALENDAR IS AN ABSTRACT CLASS, THAT'S WHY
              // THE KEYWORD NEW CAN NOT BE USED TO INITIALIZE
              cal = new GregorianCalendar();
              temp = new GregorianCalendar();
              // SETTING UP THE MENUBAR AND MENUITEMS
              bar = new JMenuBar();
              setJMenuBar(bar);
              file = new JMenu("File");
              bar.add(file);
              newDate = new JMenuItem("New Date");
              exit = new JMenuItem("Exit");
              file.add(newDate);
              file.add(exit);
              // CREATION AND INITIALIZATION OF THE MAIN CONTAINER
              // ITS LAYOUT MANAGER IS BORDERLAYOUT.
              // THERE WILL BE TWO ELEMENTS IN IT. THE BANNER WILL BE LOCATED IN
              // THE NORTH SIDE AND THE CALENDAR WILL BE LOCATED IN THE SOUTH SIDE
              Container c;
              c = getContentPane();
              c.setLayout ( new BorderLayout(5,5) );
              // INITIALIZING THE UPPER PANEL
              // THE BANNER WILL BE LOCATED THERE
              // ITS LAYOUT MANAGER WILL BE FLOWLAYOUT
              upper = new JPanel ( new FlowLayout(FlowLayout.LEFT) );
              // SETTING THE BANNER WITH THE CURRENT DATE
              banner = new String (month[cal.get(GregorianCalendar.MONTH)] + " " +
                   String.valueOf(cal.get(GregorianCalendar.DATE)) + "," + String.valueOf(cal.get(GregorianCalendar.YEAR)) );
              dateBanner = new JLabel(banner);
              upper.add(dateBanner);//ADDING THE BANNER TO THE UPPER PANEL
              // GETTING LIMITS TO BUILD THE CALENDAR USING FOR LOOPS
              // GETTING THE MAXIMUM NUMBER OF DAYS FOR A GIVEN DATE
              maxDay = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
              minDay = 0; // 0 is the equivalent of the first day of the month
              curDate = cal.get(GregorianCalendar.DATE);
              firstDay = firstDayOfMonth ( cal,temp ); //GETTING THE NUMERIC VALUE OF THE FIRST DAY
                                                           //OF THE MONTH: SUNDAY=1,MONDAY=2, AND SO ON
              // SETTING UP THE LAYOUT MANAGER FOR THE INFERIOR PANELS
              lower = new JPanel ( new BorderLayout() );
              lowerDays = new JPanel ( new GridLayout(1,7));
              lowerGregorianCalendar = new JPanel ( new GridLayout(5,7,5,5) );
              // PUTTING THE DAYS OF THE WEEK IN THE CALENDAR
              for ( int i=0 ; i<7 ; i++ )
                   lowerDays.add(new JLabel(dayWeek));
              lower.add(lowerDays,BorderLayout.NORTH);//ADDING THE DAYS OF THE WEEK TO THE LOWER PANEL
              // BUILDING THE CALENDAR USING THE PRIOR DEFINED LIMITS AND A FOR LOOP
              calDays = new JTextArea [50];//EVERY DAY OF THE CALENDAR IS A TEXT AREA
              for ( int i=0 ; i < (maxDay + firstDay) ; i++ )
                   calDays[i] = new JTextArea ( 3,3 );
                   calDays[i].setEditable(false);
                   if ( (i-firstDay) != curDate-1)
                        calDays[i].setBackground(Color.yellow);
                   else
                        calDays[i].setBackground(Color.red);
                   if ( i >= firstDay )
                        calDays[i].setText(String.valueOf(i-firstDay+1) );
                   lowerGregorianCalendar.add(calDays[i]);
              lower.add(lowerGregorianCalendar);
              c.add(upper,BorderLayout.NORTH);//ADDING THE UPPER PANEL TO THE CONTAINER
              c.add(lower,BorderLayout.SOUTH);
              setVisible(true);
              setSize(500,400);
         // THIS METHOD RETURNS THE EQUIVALENT OF THE FIRST DAY OF THE MONTH
         // SUNDAY=1,MONDAY=2 AND SO ON
         public int firstDayOfMonth ( GregorianCalendar cal, GregorianCalendar temp )
              // CREATING A TEMPORAL CALENDAR AND INITIALIZING IT WITH THE CAL VALUE
              //GregorianCalendar temp= temp.getInstance();
              // SETTING TEMP TO THE FIRST DAY OF THE MONTH
              temp.set(cal.get(GregorianCalendar.YEAR), cal.get( GregorianCalendar.MONTH) , 1 );
              // RETURNING THE NUMERIC VALUE OF THE FIRST DAY OF THE MONTH
              // SUNDAY=1,MONDAY=2, AND SO ON
              return temp.get(GregorianCalendar.DAY_OF_WEEK);
         public static void main ( String args[] )
              Assign2 app = new Assign2();
              app.reSize(550,450);
              app.addWindowListener(
                   new WindowAdapter()
                        public void windowClosing (WindowEvent e)
                             System.exit(0);

    Gustavo,
    I'm in the middle of writing such a calendar, but I've modularized things a bit. I start with a JFrame like you, and then add to it a class "CalendarPanel" built from a JPanel which holds all the buttons, combo boxes, etc.
    But try this: just after instantiating your JFrame object, call its show() method.

  • Removing and adding panels to a jframe

    i have tried using remove all to remove a panel which is on my mainpanel which is on the jframe. when i do though, only the area where the menu was is removed. The components on the frame are not accessible. i want to then add another frame. this does not seem to work. i have tried using removeAll(), validate(), repaint(). i am probably not using them correctly or in the right order, so can anyone help me out?????????

    If you have added the JPanel to the JFrame and the components to the JPanel the removeAll() should work.
    public void actionPerformed(ActionEvent e){
       if(e.getSource()==myButton){
           content.removeAll();
           content.add(panel2);
      }

  • Multithreaded Pacman: only last animated panel added to JFrame is displaye

    Hello,
    I am making a multithreaded pacman game. Pacman and each of the ghosts run in a separate thread.
    However, only the last item (ie. pacman or one of the ghosts) added to the JFrame is displaying in the maze. (pacman and each of the ghosts are subclasses of JPanel). For example, if I do:
    add(pacman);
    add(orangeGhost);
    add(redGhost);
    only the red ghost animation will appear on the maze(which is also a subclass of JPanel).
    I have tried adding the ghosts to pacman and then adding pacman i.e. pacman.add(redGhost); add(pacman); but this still doesn't work - only pacman is showing in the maze.
    Each thread runs fine on its own, but only the last one added is displaying.
    Any help is much appreciated.

    Hi,
    JFrame uses the BoderLayout layout manager, and when you add a JPanel after the other inside your JFrame they will get put one on top of other. None of the layout manager let you overlap components with transparency as far as I know. Also your JPanels are not transparent but opaque.
    I think what you need is to "paint" your game on a JPanel o canvas, take a look at this tutorial:
    http://javaboutique.internet.com/tutorials/Java_Game_Programming/
    Keep asking around, people with more experience can help you on this forum.
    Regards,

  • What are the consequences of having more than one iphone connected to the same itunes on 1 computer?

    I'm wondering if there are any weird problems or glitches to be expected when 2 iphones are connected to the same itunes on a single computer.  My wife and I both have iphone 5's with separate apple IDs.  We only have one computer with one user account so both iphones are signed in to the same itunes.  This seems to be a totally normal thing to do.  Both phones appear when I open itunes and itunes lets me choose which phone I want to look at the information for, sync, etc.  However I have noticed some unusual behavior.  For example, sometimes when I am checking apps or installing new apps on my iphone, even when I am away from home and our computer, her apple ID will show up.  I have never entered her ID into my phone.  Are there any other quirks I should know about and is there anything else to watch out for when we both have our phones connected to one computer in this way?

    You need to create a user account for your wife (or yourself depending on who has the current user account). When syncing, each of you should sign in as a separate user, login to iTunes and then sync. I had this problem when my sister got an iPhone. When we did her initial sync, everything on my iPhone showed up on hers. Apple gave me this solution.

  • Passing parameter between jpanel and jframe

    Hi guys,
    First time posting, so please be nice! :p
    Basically, the problem i'm having:
    I have created a JFrame class, which adds some JPanels to itself to start with (basic layout stuff).
    This JFrame is created and instantiated in main.java, and just displays the basic stuff that i've added.
    On the JFrame are a number of JButtons, and when you click on the JButton each JButton it adds a custom JPanel to the main JFrame. Basically, it provides an easy way to produce a kind of menu system using the JPanels.
    The problem i have, is that each time a textbox is clicked inside one of the custom JPanels, i want it to pass the name of the textbox and jpanel back to a method setLastTextBox() in the JFrame class.
    I tried:
    private void jTextPane1FocusGained(java.awt.event.FocusEvent evt) {
        super.setLastTextBox()
    }But super. is not the correct call. I'm sure its something pretty simple but i can't think what it is, and i tried googling it to no avail.
    I would be extremely greatful if someone could put me back on the right path!
    Thanks,
    --Mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi, Mark
    I hope I understood you rihgt.
    I think that you should add Focus Listeners to the text boxes, rather than panels and create a method setLastTextBox(String panelName, String textBoxName)
    and just write something like that
    textField1.addFocusListener(new FocusAdapter(){
                public void focusGained(FocusEvent e) {
                    String textFieldName = ((JTextField)e.getSource()).getName();
                    String panelName = ((JTextField)e.getSource()).getParent().getName();
                     setLastTextBox(textFieldName, panelName);
            });    that is if you write this code inside your frame class
    otherwise you can get to your frame, by calling the method getParent() and checking its class until its not YourFrameClass (or JFrame) and then just cast it and call the method.
    I hope I was clear
    Ksenia

  • How to scroll panels using scrollpane?

    i am having two panels containing different images in a main panel.
    my problem is that due to big size only one panel is visible in run time so i want to add scrollbar to the main panel.
    i have used scrollpane for the main panel but i am getting confused that at which event i should put the code of repainting the visible area.
    can anybody tell me how to implement this.
    plz... help

    gaurav_mishra wrote:
    actually i am working in netbeans so i don't know where is the paint method of the panel.can anybody plz help me get rid of this problemApparently we were all mistaken by your description, it looked like you were writing a custom JPanel subclass, with a custom paintComponent() method that would draw the images...
    I don't know how you display images in a Panel with NetBeans, but presumably it re-uses some existing JComponent and it doesn't have to generate a paintComponent() method.
    At that step you should consider the very first reply: please post some code, the shortest running example that demonstrates your problem.
    If you're reluctant, try a simple scroll example: put a single JButton in a JPanel with a FlowLayout, using an image as the button's icon. Stuff this panel into a JScrollPane, itslef in a JFrame, run the app and resize the JFrame. Check whether the button displays appropriately. If it does, try to check what's different with your problematic case.
    I like NetBeans (or merely, NetBeans's GUI designer), but it's not the best way to learn Swing programming, which looks like what you're doing.

  • Is there a problem with JFrame and window listeners?

    As the subject implies, i'm having a problem with my JFrame window and the window listeners. I believe i have implemented it properly (i copied it from another class that works). Anyway, none of the events are caught and i'm not sure why. Here's the code
    package gcas.gui.plan;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    import java.util.Hashtable;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import gcas.plandata.TaskData;
    import gcas.util.GCASProperties;
    import gcas.gui.planlist.MainPanel;
    * MainFrame extends JPanel and is the main class for the plan details window
    public class MainFrame extends JFrame implements WindowListener
         * the container for this window
        private Container contentPane;
         * a string value containing the name of the plan being viewed
        private String labelText;
         * a string value containing the name of the window (GCAS - plan list)
        private static String title;
         * an instance of JDialog class
        private static MainFrame dialog;
         * hashTable that correlates the task name to its id as found in the
         * plan
        private Hashtable taskNameToId = new Hashtable();
         * an instance of taskSetPane.  This is the current instance of taskSetPane
         * being viewed
        private PlanTaskSet currentPane;
         * instance of TaskData class.  Each instance will hold information on
         * an individual task
        private TaskData taskData;
         * hashTable containing instances of the taskSetPane class
        private Hashtable taskSetPanes = new Hashtable();
         * an instance of the OuterPanel class
        OuterPanel mainPanel;
         * an instance of the ButtonPanel class
        ButtonPanel buttonsPanel;
         * an instance of the LeftPanel class
        LeftPanel leftPanel;
         * an instance of the the GCASProperties class
        GCASProperties gcasProps;
        private static MainFrame thisPlanMain = null;
        private MainPanel planListMain;
         * constructor for MainFrame
         * @param frame the parent frame calling this class
         * @param locationComp the location of the component that initiated the opening of the dialog
         * @param labelText the name of the plan that is being viewed
         * @param title title of window
        private MainFrame(JFrame frame, Component locationComp, String labelText,
                String title)
            super(title);
            gcasProps = GCASProperties.getInstance();
            mainPanel = new OuterPanel(labelText, currentPane,
                    taskNameToId, taskSetPanes);
            leftPanel = mainPanel.getLeftPanel();
            System.out.println("LABLE: " + labelText);
            leftPanel.setMainPanelContents();
            buttonsPanel = new ButtonPanel(labelText, taskSetPanes,
                    taskNameToId, leftPanel);
            contentPane = getContentPane();
            contentPane.add(mainPanel, BorderLayout.CENTER);
            contentPane.add(buttonsPanel, BorderLayout.PAGE_END);
            this.addWindowListener(this);
            this.labelText = labelText;
            pack();
            setLocationRelativeTo(locationComp);
            this.setVisible(true);
            planListMain = MainPanel.getInstance();
            planListMain.setVisible(false);
        public static MainFrame getInstance(JFrame frame, Component locationComp, String labelText,
                String title)
            if (thisPlanMain == null)
                thisPlanMain = new MainFrame(frame, locationComp, labelText,
                        title);
            return thisPlanMain;
        public static MainFrame getDialogObject()
        {   //from the location this is called (ButtonPanel), this will never
            //be null
            return thisPlanMain;
        public static void setABMDDialogNull()
            thisPlanMain = null;
         * returns an instance of MainFrame
         * @return MainFrame instance
        public static MainFrame getDialog()
            return dialog;
         * setter for MainFrame
         * @param aDialog a MainFrame instance
        public static void setDialog(MainFrame aDialog)
            dialog = aDialog;
         * window opened event
         * @param windowEvent the window event passed to this method
        public void windowOpened(WindowEvent windowEvent)
         * The window event when a window is closing
         * @param windowEvent the window event passed to this method
        public void windowClosing(WindowEvent windowEvent)
            gcasProps.storeProperties("PlanList");
            MainPanel abmd = MainPanel.getInstance();
    //        planMain = this.getDialogObject();
    //        if(planMain != null)
    //            planMain.setVisible(false);
    //            abmd.setVisible(true);
    //            planMain.setABMDDialogNull();
            if(this.getDialogObject()!= null)
                abmd.setVisible(true);
                setVisible(false);
                setABMDDialogNull(); 
         * Invoked when the Window is set to be the active Window
         * @param windowEvent the window event passed to this method
        public void windowActivated(WindowEvent windowEvent)
         * Invoked when a window has been closed as the result of calling dispose on the window
         * @param windowEvent the window event passed to this method
        public void windowClosed(WindowEvent windowEvent)
         * Invoked when a Window is no longer the active Window
         * @param windowEvent the window event passed to this method
        public void windowDeactivated(WindowEvent windowEvent)
            System.out.println("HI");
         * Invoked when a window is changed from a minimized to a normal state
         * @param windowEvent the window event passed to this method
        public  void windowDeiconified(WindowEvent windowEvent)
            //we could have code here that changed the way alerts are done
           System.out.println("Invoked when a window is changed from a minimized to a normal state.");
         * Invoked when a window is changed from a normal to a minimized state
         * @param windowEvent the window event passed to this method
        public  void windowIconified(WindowEvent windowEvent)
            //we could have code here that changed the way alerts are done
    //        System.out.println("Invoked when a window is changed from a normal to a minimized state.");
    }anyone know whats wrong?

    It turned out that my ide was running the old jar and not updating it, so no matter what code i added, it wasn't being seen. Everything should be fine now.

  • How to call a private method in a JFrame

    I have a Frame which has some properties like its size, bgcolor plus other parameters, as instance variables. There is a button on the Frame with the caption : "set properties". When one clicks on that button, a new frame should appear via which a user can change the values of the parameters of the main Frame (i.e size, bgcolor,..etc). The user would input the new values in the textfields or radio buttons that are on the new frame, and then click a submit button, which has to exist on the same NFrame. How can I do that so that when the submit button is pressed, the parameters values are updated and so is the display view ?
    I made it this way : I created 2 classes, the main frame and the new Frame. I made the new Frame an instance variable of the main Frame. When the user clicks the " set properties" button on the main Frame, the new Frame is shown. The user enters new values for some of the parameters and clicks submit. The parameters in the new Frame are updated. UP TO HERE EVERYTHING WENT JUST FINE. Now, there is a private method in the main frame that changes the color, size, ...etc of the main frame according to the values stored in the instance variables color, size,...etc. THE QUESTION IS: How can the new Frame display the changes after the values have been updated ? That is, how can it call the "private" method in the main class?? Should the new class be a child class of the main class to be able to access it's private methods ??

    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    import javax.swing.*;
    public class CallingHome
        SkinMod skinMod;
        JPanel panel;
        public CallingHome()
            // send reference so SkinMod can call methods in this class
            skinMod = new SkinMod(this);
            JButton change = new JButton("change properties");
            change.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    skinMod.showDialog();
            JPanel north = new JPanel();
            north.add(change);
            panel = new JPanel();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(north, "North");
            f.getContentPane().add(panel);
            f.setSize(300,100);
            f.setLocation(200,200);
            f.setVisible(true);
        public void setBackground(Color color)
            panel.setBackground(color);
            panel.repaint();
        public static void main(String[] args)
            new CallingHome();
    class SkinMod
        CallingHome callHome;
        Random seed;
        JDialog dialog;
        public SkinMod(CallingHome ch)
            callHome = ch;
            seed = new Random();
            createDialog();
        public void showDialog()
            if(!dialog.isShowing())
                dialog.setVisible(true);
        private void createDialog()
            JButton change = new JButton("change background");
            change.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    callHome.setBackground(getColor());
                    dialog.dispose();
            JPanel p = new JPanel();
            p.add(change);
            dialog = new JDialog();
            dialog.getContentPane().add(p);
            dialog.setSize(200,100);
            dialog.setLocation(525,200);
        private Color getColor()
            return new Color(seed.nextInt(0xffffff));
    }

  • Help needed in refreshing a Panel

    I have created a GUI, which is having 2 windows. window1 is having a panel,that displays an array of buttons. from window1, clkicking "add" button window2 appears. in window2 I am adding new values to the button array of window1. window2 is having a button "ok".
    My requirement is when I'll add new buttons thru window2 to the button array in window1, and after clicking the "ok" button in window2, the window1 should be refreshed with the new button in the button array.
    I have already tried one solution for it.I put the creation, addition of buttons to panel & its visibility in a function and I called the function while clicking the "ok" button in window2. But it is showing a list of event dispatch error.
    If any of you have any better idea, please let me know soon.so that I can proceed further.
    Regards

    Do the following in window2 after adding the values to window1;
    window1.repaint();
    window1.validate();Hope this fixes your problem....And if not, then I need some code to work it.
    Cheers,
    Bolo

  • Hello everybody, Problem with Two panel in a Frame

    This is my first mail in this forum.I'm trying to learn java myself & have a problem in adding more than one panel in a JFrame.
    i should be able to add one panel which occupies 3/4 of a frame and another panel occupies the rest.
    Thanx in advance for anyone who helps me in sorting out this problem.

    You can use for example the GridLayout
    In your JFrame constructor, add lines below, it will add 2 colored panel in your frame
    Container container = getContentPane();
    container.setLayout(new GridLayout(1,2)); // 1 row, 2 cols
    JPanel panel1 = new JPanel();
    panel1.setBackground(Color.red);
    container.add(panel1);
    JPanel panel2 = new JPanel();
    panel2.setBackground(Color.green);
    container.add(panel2);

  • How to define Side Panels for linked to Child Window Applications

    We are trying to use the NWBC Side Panel with PPM 6.0 in NWBC 3.5.  We have a Role that has a menu defined that gives the users a link to the INM_WORKCENTER_APP which displays the current user's Tasks in a table.
    When we click on a task in the table it opens the task details using the CPROJECTS_FPM application in a new window.  This new window that opens up doesn't have any of the Side Panels that we have defined on the role with the main menu links.
    We have tried to add the side panel using different application alias and at different levels in the Role, but can't get a Side Panel to show up on the child window.  We even tried to switch the window to open INPLACE in the main window and it still switches to no side panels.  The only side panels we are able to see is side panels that the user has manually added under connections and the Data Context Viewer side panels.
    Is NWBC capable of having side panels to be defined to be available for these linked to child applications that are called from a main application screen?  If so, what is the possible configurations we need to make on the role for this to work properly?
    Thanks in advance for any help!

    Wanted to close this thread with the solution that worked for us.
    We had to change the Launchpad configuration for Role CPROJECTS Instance OIF.  We changed the Application from a Web Dynpro ABAP type to Object Based Navigation.  Set the Application Parameters Business Object to PROJECT and Operation to DISPLAY.
    Then for our role defined in PFGC for our NWBC, we added a new menu item to the Web Dynpro application CPROJECTS_FPM with Configuration CPROJECTS_FPM.  Then under Object Based Navigation we set the Object Type to PROJECT and Method to DISPLAY to match what we set above in the Launchpad.  Then set the menu item to be invisible since we didn't want it to show to users.
    Now when we launch the child window it uses OBN and sees the definition in our role and utilizes the same Side Panel definitions defined for the role.

Maybe you are looking for