JDesktopPane & JToolBar

Hello,
I'm trying to put a JToolBar and a JPanel (to represent a status bar) to my JDesktopPane, but it doesn't work.
So I tried several solutions :
- one time the JToolBar appears but the 2 JInternalFrames don't work perfectly : when you click on the title bar of one of those JInternalFrames, it fills all the width and height of the JDesktopPane !?!
- and now, the JToolBar and the JPanel don't appear on the screen.
It seems that it depends the place where I put "setContent(desktop)". I don't know why. I tried to put it other ways, and there's always a thing that don't work !
Please if you have any idea, help me.
Thanks
Yann
Here's my code (it is very inspired of the tutorial) :
public class InterfaceGraphique extends JFrame {
public InterfaceGraphique () {
super("title");
Container content = getContentPane();     
content.setLayout(new BorderLayout());
desktop = new JDesktopPane(); //a specialized layered pane
//Make dragging faster:
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
createFrame(); // creation of my 2 internal frames          
buildUI(content);     // GUI of the principal frame
setContentPane(desktop);
private void buildUI(Container content) {
panelStatusBar = new JPanel();
panelStatusBar.setBorder(BorderFactory.createLoweredBevelBorder());
statusBar = new JLabel("Welcome", JLabel.LEFT);
panelStatusBar.add(statusBar);
setJMenuBar(createMenuBar());          
toolBar = new JToolBar();
addButtons(toolBar);
content.add(toolBar, BorderLayout.NORTH);
content.add(panelStatusBar, BorderLayout.SOUTH);
Thank you for any help.

Don't set the desktop as the content of the frame. Instead use a JPanel with a BorderLayout to which you add the Tool and Status bar as you are doing and also add desktop with BorderLayout.CENTER. You'll need to ensure that your internal frames are added to the desktop and not the JPanel.

Similar Messages

  • JButtons in JToolbar don't work with JApplet- why?

    I made a JApplet which has a toolbar, populated with burrons that manipulate data from text files. The programs works perfectly when it is not a JApplet. However, once I converted it to a JApplet it does nothing. The code was exactly the same, but, pressing buttons does nothing when it is an applet. here is the complete code;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    public class CSE extends JApplet implements ActionListener, ItemListener
    //GUI COMPONENTS
    //ToolBar components
    JToolBar mainSelect = new JToolBar("Materials");
    JButton materials;
    String materialNames[] = {"Fur Square", "Bolt of Linen", "Bolt of Damask", "Bolt of Silk", "Glob of Ectoplasm", "Steel Ingot", "Deldrimor Steel Ingot", "Monstrous Claw", "Monstrous Eye", "Monstrous Fang", "Ruby", "Lump of Charcoal", "Obsidian Shard", "Tempered Glass Vial", "Leather Square", "Elonian Leather Square", "Vial of Ink", "Roll of Parchment", "Roll of Vellum", "Spiritwood Plank", "Amber Chunk", "Jadeite Shard"};
    ImageIcon materialIcons;
    //Graphic components
    JDesktopPane mainGraph = new JDesktopPane();
    JPanel dailyGraph = new JPanel();
    JPanel weeklyGraph = new JPanel();
    JPanel finalPrices = new JPanel();
    Box graphs = Box.createHorizontalBox();
    //The Console
    JFrame CSEFrame = new JFrame();
    JSplitPane mainConsoleBackdrop = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    JSplitPane dataOut = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    JTextArea prediction = new JTextArea(10,10);
    JScrollPane predictionScroll;
    Box finalPricesLabels = Box.createVerticalBox();
    Box finalPricesLay = Box.createVerticalBox();
    JLabel finalBuy = new JLabel("Net Buy Price Change: 0.00");
    JLabel finalSell = new JLabel("Net Sell Price Change: 0.00");
    JLabel buySell = new JLabel("We recommend you: N/A");
    JTextArea priceUpdate = new JTextArea(10, 10);
    JTextArea priceUpdateWeekly = new JTextArea(10, 10);
    JScrollPane priceUScrollW;
    JScrollPane priceUScroll;
    JCheckBox weeklySelect = new JCheckBox("To show weekly price changes.", false);
    JCheckBox dailySelect = new JCheckBox("To show daily price changes.", true);
    ButtonGroup dataToShow = new ButtonGroup();
    //COMPONENTS FOR DATE; OBTAINING CORRECT FOLDER
    String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    Calendar calSource = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    int day = calSource.get(Calendar.DAY_OF_MONTH);
    int month = calSource.get(Calendar.MONTH);
    int year = calSource.get(Calendar.YEAR);
    int monthCheck [] = {Calendar.JANUARY, Calendar.FEBRUARY, Calendar.MARCH, Calendar.APRIL, Calendar.MAY, Calendar.JUNE, Calendar.JULY, Calendar.AUGUST, Calendar.SEPTEMBER, Calendar.OCTOBER, Calendar.NOVEMBER, Calendar.DECEMBER};
    int dayS = day;
    int monthS = month;
    int yearS = year;
    //if there is file found
    boolean proceed = false;
    //int data for analysis
    int buyPrice;
    int currentBuyPrice;
    int sellPrice;
    int currentSellPrice;
    boolean weekly = false;
    //tools for parsing and decoding input
    String inputS = null;
    String s = null;
    Scanner [] week = new Scanner[7];
    Scanner scanner;
    int position = 0;
    //weekly tools
    String weekPos[] = {"Seventh", "Sixth", "Fifth", "Fourth", "Third", "Second", "First"};
    int dayOfWeek = 0; //0 = 7    1 = 6...
                    public JButton getToolBarButton(String s)
                        String imgLoc = "TBar Icons/" +s +".gif";
                        java.net.URL imgURL = CSE.class.getResource(imgLoc);
                        JButton button = new JButton();
                        button.setActionCommand(s);
                        button.setToolTipText(s);
                        button.addActionListener(this);
                        if(imgURL != null)
                            button.setIcon(new ImageIcon(imgURL, s));
                        else
                            button.setText(s);
                            System.err.println("Couldn't find; " +imgLoc);
                        return button;
                        public CSE()
                                   // super("Test CSE");
                                    //CSEFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                    for(int x=0; x<materialNames.length; x++)
                                        materials = getToolBarButton(materialNames[x]);
                                        mainSelect.add(materials);
                                    //checkBoxes
                                    dataToShow.add(weeklySelect);
                                    dataToShow.add(dailySelect);
                                    weeklySelect.addItemListener(this);
                                    dailySelect.addItemListener(this);
                                    // sizes
                                    setSize(850, 850);
                                    //colors and fonts
                                    weeklyGraph.setBackground(new Color(250, 30, 40));
                                    dailyGraph.setBackground(new Color(100, 40, 200));
                                    //text Manip.
                                    prediction.setLineWrap(true);
                                    priceUpdate.setLineWrap(true);
                                    //scrolling
                                    predictionScroll = new JScrollPane(prediction, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                    priceUScroll = new JScrollPane(priceUpdate, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                    priceUScrollW = new JScrollPane(priceUpdateWeekly, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                    //main splitpane config.
                                    mainConsoleBackdrop.setOneTouchExpandable(true);
                                    mainConsoleBackdrop.setResizeWeight(.85);
                                    //placement and Layout
                                    //GraphLayout
                                    graphs.add(Box.createHorizontalStrut(10));
                                    graphs.add(dailyGraph);
                                    graphs.add(Box.createHorizontalStrut(10));
                                    graphs.add(weeklyGraph);
                                    graphs.add(Box.createHorizontalStrut(10));
                                    dataOut.setRightComponent(predictionScroll);
                                    //consoleData layout
                                    finalPricesLabels.add(Box.createVerticalStrut(10));
                                    finalPricesLabels.add(finalBuy);
                                    finalPricesLabels.add(Box.createVerticalStrut(10));
                                    finalPricesLabels.add(finalSell);
                                    finalPricesLabels.add(Box.createVerticalStrut(10));
                                    finalPricesLabels.add(buySell);
                                    finalPricesLay.add(finalPricesLabels);
                                    finalPricesLay.add(Box.createVerticalStrut(10));
                                    finalPricesLay.add(weeklySelect);
                                    finalPricesLay.add(dailySelect);
                                    finalPricesLay.add(priceUScroll);
                                    dataOut.setLeftComponent(finalPricesLay);
                                    mainConsoleBackdrop.setTopComponent(graphs);
                                    mainConsoleBackdrop.setBottomComponent(dataOut);
                                    getContentPane().add(mainConsoleBackdrop);
                                    getContentPane().add(mainSelect, BorderLayout.NORTH);
                                    //visibility
                                   // CSEFrame.setVisible(true);
                                    //return(CSEFrame);
                                        public void actionPerformed(ActionEvent e)
                                            getMonth();
                                            inputS = e.getActionCommand();
                                            FileReader newRead = null;
                                                    try {
                                                           newRead = new FileReader(monthS +"-" +dayS +"-" +yearS +"/" +inputS +".dat");
                                                           proceed = true;
                                                        catch(FileNotFoundException f)
                                                           System.out.println("File not found");
                                                           proceed = false;
                                          if(proceed)
                                          BufferedReader bufferedReader = new BufferedReader(newRead);
                                          scanner  = new Scanner(bufferedReader);
                                          scanner.useDelimiter("\n");
                                         //starts daily analysis
                                          getPrice(scanner);
                                        //starts weekly analysis
                                          weekly(inputS);
                                    public void itemStateChanged(ItemEvent e)
                                        if(weeklySelect.isSelected())
                                        priceUpdateWeekly.setText("");
                                        finalPricesLay.remove(priceUScroll);
                                        finalPricesLay.add(priceUScrollW);
                                        finalPrices.updateUI();
                                        else
                                            priceUpdate.setText("");
                                            finalPricesLay.remove(priceUScrollW);
                                            finalPricesLay.add(priceUScroll);
                                            finalPrices.updateUI();
                                    public void weekly(String inputS)
                                        weekly = true;
                                        for(int x = 0; x < 7; x++)
                                           dateToUse(month, day, year, (x+1));
                                            try
                                                    FileReader weeklySource = new FileReader(monthS +"-" +dayS +"-" +year +"/" +inputS +".dat");
                                                    BufferedReader weeklyBuffer = new BufferedReader(weeklySource);
                                                    week[x] = new Scanner(weeklyBuffer);
                                                    week[x].useDelimiter("\n");
                                                    getPrice(week[x]);
                                             catch(FileNotFoundException f)
                                                JOptionPane.showMessageDialog(this, "No such weekly files- going back;" +(x+1) +"days");
                                        weekly = false;
                                        dateReset();
                                    public void getPrice(Scanner scanner)
                                        while(scanner.hasNextLine())
                                            //puts into string the next scan token
                                            String s = scanner.next();
                                            //takes the scan toke above and puts it into an editable enviroment
                                            String [] data = s.split("\\s");
                                            for(position = 0; position < data.length; position++)
                                                        //Scanner test to make sure loop can finish, otherwise "no such line" error
                                                        if(scanner.hasNextLine()==false)
                                                        scanner.close();
                                                        break;
                                                           /*Starts data orignazation by reading from each perspective field
                                                            * 1 = day
                                                            * 2 = day of month
                                                            * 3 = month
                                                            * 4 = year
                                                           if(position == 0 && weekly == false)
                                                               String dayFromFile = data[position];
                                                                int dayNum = Integer.parseInt(dayFromFile);
                                                              priceUpdate.append(days[dayNum-1] +" ");
                                                           else if(position == 1  && weekly == false )
                                                              priceUpdate.append(data[position] + "/");
                                                           else if(position == 2 && weekly == false)
                                                              priceUpdate.append(data[position] + "/");
                                                            else if(position == 3 && weekly == false)
                                                                priceUpdate.append(data[position] +"\n");
                                                           //if it is in [buy] area, it prints and computes
                                                            else if(position == 7)
                                                                //obtains string for buy price and stores it, then prints it
                                                                String buy = data[position];
                                                            if(weekly == false)
                                                            priceUpdate.append("Buy: " +buy +"\n" );
                                                             //converts buy to string
                                                            currentBuyPrice = Integer.parseInt(buy);
                                                            //eliminates problems caused by no data from server- makes the price 0
                                                            if(currentBuyPrice < 0)
                                                                currentBuyPrice = 0;
                                                            //if it is greater it adds
                                                            if(currentBuyPrice > buyPrice)
                                                                     buyPrice += currentBuyPrice;
                                                            //if it is equal [there is no change] then it does nothing    
                                                            if(currentBuyPrice == buyPrice)
                                                                buyPrice +=0;
                                                            //if there is a drop, it subtracts
                                                               else
                                                                   buyPrice -= currentBuyPrice;
                                                            //if it is in [sell] area, it prints, and resets the position to zero because line is over
                                                            else if(position == 8)
                                                                //puts sell data into string and prints it
                                                                String sell = data[position];
                                                                if(weekly == false)
                                                                priceUpdate.append("Sell: " + sell +"\n");
                                                                //turns sell data into int.
                                                              currentSellPrice = Integer.valueOf(sell).intValue();;
                                                            //gets rid of problems caused by no data on server side- makes it 0 
                                                            if(currentSellPrice < 0)
                                                                currentSellPrice = 0;
                                                            //adds if there is an increase
                                                            if(currentSellPrice > sellPrice)
                                                                     sellPrice += currentSellPrice;
                                                            //does nothing if it is the same    
                                                            if(currentSellPrice == sellPrice)
                                                                sellPrice +=0;
                                                            //subtracts if there is drop
                                                               else
                                                                   sellPrice -= currentSellPrice;
                                                                //further protection against "No such line" and moves it down
                                                               if(scanner.hasNextLine() == true)
                                                                scanner.nextLine();
                                                                //if scanner is finished, prints out all lines
                                                               if(scanner.hasNextLine() == false && weekly == false)
                                                                finalBuy.setText("Net Buy Price Change: "+buyPrice);
                                                                finalSell.setText("Net Sell Price Change: " +sellPrice);
                                                                buyPrice = 0;
                                                                sellPrice = 0;
                                                                position = data.length;
                                                               else if(scanner.hasNextLine() == false && weekly == true)
                                                                   priceUpdateWeekly.append("\n" +weekPos[dayOfWeek] +" day of the week ended with; \nBuy Price;" +buyPrice +"\nSell Price;" +sellPrice);
                                                                   buyPrice = 0;
                                                                   sellPrice = 0;
                                                                   position = data.length;
                                                                   dayOfWeek++;
                                                                   if(dayOfWeek > 6)
                                                                   dayOfWeek = 0;
                                public void getMonth()
                                    for(int x=0; x < monthCheck.length; x++)
                                        if(month == monthCheck[x])
                                              monthS = (x+1);
                                              x = monthCheck.length;
                                 public void dateToUse(int month, int day, int year, int increment)
                                 //set day of source
                                  dayS = (day - increment);
                                //if day of source is less then O then we have moved to another month 
                                if(dayS <= 0)
                                        //checks the difference between how much we have incremented and the day we have started; this tells us how far into the new month we are
                                        int incrementDay = increment - day;
                                        //decrements month
                                        monthS--;
                                        //if month is less then zero, then we have moved into another year and month has become 12
                                        if(monthS <= 0)
                                            yearS--;
                                            monthS = 12;
                                        //the following looks at the current month and if it goes below it assigns the day to the proper ammount of days of the month before minus the days into the month
                                           if(month == 3)
                                               dayS = 28 - incrementDay;
                                           else if(month == 5 || month == 7)
                                               dayS = 29 - incrementDay;
                                           else if(month == 2 || month == 4 || month == 6 || month == 9 || month == 11)
                                               dayS = 31 - incrementDay;
                                            else
                                                dayS = 30 - incrementDay;
                               //resets the source date to the current date once data from the week has been reached
                                public void dateReset()
                                    dayS = day;
                                    monthS = month;
                                    yearS = year;
                     public void init()
                         //JFrame frame = new CSEFrameSet();
                        // this.setContentPane(CSEFrameSet());
                        CSE aCSE = new CSE();
    public static void main(String [] args)
    CSE cs = new CSE();
    }I have tried uploading it to a server, running it from appletviewer, and locally using the .HTML file. The GUI works fine, everything is there, however, pressing the buttons does nothing.
    Can you not use the Scanners and such with JApplets?
    Yes, the directories are good.
    EDIT EDIT EDIT; OK, it works with appletviewer, but still doesn't work when it is published.
    Message wa

    I can't seem to edit the post anymore, here it is again;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    public class CSE extends JApplet implements ActionListener, ItemListener
    //GUI COMPONENTS
    //ToolBar components
    JToolBar mainSelect = new JToolBar("Materials");
    JButton materials;
    String materialNames[] = {"Fur Square", "Bolt of Linen", "Bolt of Damask", "Bolt of Silk", "Glob of Ectoplasm", "Steel Ingot", "Deldrimor Steel Ingot", "Monstrous Claw", "Monstrous Eye", "Monstrous Fang", "Ruby", "Lump of Charcoal", "Obsidian Shard", "Tempered Glass Vial", "Leather Square", "Elonian Leather Square", "Vial of Ink", "Roll of Parchment", "Roll of Vellum", "Spiritwood Plank", "Amber Chunk", "Jadeite Shard"};
    ImageIcon materialIcons;
    //Graphic components
    JDesktopPane mainGraph = new JDesktopPane();
    JPanel dailyGraph = new JPanel();
    JPanel weeklyGraph = new JPanel();
    JPanel finalPrices = new JPanel();
    Box graphs = Box.createHorizontalBox();
    //The Console
    JFrame CSEFrame = new JFrame();
    JSplitPane mainConsoleBackdrop = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    JSplitPane dataOut = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    JTextArea prediction = new JTextArea(10,10);
    JScrollPane predictionScroll;
    Box finalPricesLabels = Box.createVerticalBox();
    Box finalPricesLay = Box.createVerticalBox();
    JLabel finalBuy = new JLabel("Net Buy Price Change: 0.00");
    JLabel finalSell = new JLabel("Net Sell Price Change: 0.00");
    JLabel buySell = new JLabel("We recommend you: N/A");
    JTextArea priceUpdate = new JTextArea(10, 10);
    JTextArea priceUpdateWeekly = new JTextArea(10, 10);
    JScrollPane priceUScrollW;
    JScrollPane priceUScroll;
    JCheckBox weeklySelect = new JCheckBox("To show weekly price changes.", false);
    JCheckBox dailySelect = new JCheckBox("To show daily price changes.", true);
    ButtonGroup dataToShow = new ButtonGroup();
    //COMPONENTS FOR DATE; OBTAINING CORRECT FOLDER
    String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    Calendar calSource = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    int day = calSource.get(Calendar.DAY_OF_MONTH);
    int month = calSource.get(Calendar.MONTH);
    int year = calSource.get(Calendar.YEAR);
    int monthCheck [] = {Calendar.JANUARY, Calendar.FEBRUARY, Calendar.MARCH, Calendar.APRIL, Calendar.MAY, Calendar.JUNE, Calendar.JULY, Calendar.AUGUST, Calendar.SEPTEMBER, Calendar.OCTOBER, Calendar.NOVEMBER, Calendar.DECEMBER};
    int dayS = day;
    int monthS = month;
    int yearS = year;
    //if there is file found
    boolean proceed = false;
    //int data for analysis
    int buyPrice;
    int currentBuyPrice;
    int sellPrice;
    int currentSellPrice;
    boolean weekly = false;
    //tools for parsing and decoding input
    String inputS = null;
    String s = null;
    Scanner [] week = new Scanner[7];
    Scanner scanner;
    int position = 0;
    //weekly tools
    String weekPos[] = {"Seventh", "Sixth", "Fifth", "Fourth", "Third", "Second", "First"};
    int dayOfWeek = 0; //0 = 7 1 = 6...
    public JButton getToolBarButton(String s)
    String imgLoc = "TBar Icons/" +s +".gif";
    java.net.URL imgURL = CSE.class.getResource(imgLoc);
    JButton button = new JButton();
    button.setActionCommand(s);
    button.setToolTipText(s);
    button.addActionListener(this);
    if(imgURL != null)
    button.setIcon(new ImageIcon(imgURL, s));
    else
    button.setText(s);
    System.err.println("Couldn't find; " +imgLoc);
    return button;
    public CSE()
    // super("Test CSE");
    //CSEFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    for(int x=0; x<materialNames.length; x++)
    materials = getToolBarButton(materialNames[x]);
    mainSelect.add(materials);
    //checkBoxes
    dataToShow.add(weeklySelect);
    dataToShow.add(dailySelect);
    weeklySelect.addItemListener(this);
    dailySelect.addItemListener(this);
    // sizes
    setSize(850, 850);
    //colors and fonts
    weeklyGraph.setBackground(new Color(250, 30, 40));
    dailyGraph.setBackground(new Color(100, 40, 200));
    //text Manip.
    prediction.setLineWrap(true);
    priceUpdate.setLineWrap(true);
    //scrolling
    predictionScroll = new JScrollPane(prediction, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    priceUScroll = new JScrollPane(priceUpdate, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    priceUScrollW = new JScrollPane(priceUpdateWeekly, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    //main splitpane config.
    mainConsoleBackdrop.setOneTouchExpandable(true);
    mainConsoleBackdrop.setResizeWeight(.85);
    //placement and Layout
    //GraphLayout
    graphs.add(Box.createHorizontalStrut(10));
    graphs.add(dailyGraph);
    graphs.add(Box.createHorizontalStrut(10));
    graphs.add(weeklyGraph);
    graphs.add(Box.createHorizontalStrut(10));
    dataOut.setRightComponent(predictionScroll);
    //consoleData layout
    finalPricesLabels.add(Box.createVerticalStrut(10));
    finalPricesLabels.add(finalBuy);
    finalPricesLabels.add(Box.createVerticalStrut(10));
    finalPricesLabels.add(finalSell);
    finalPricesLabels.add(Box.createVerticalStrut(10));
    finalPricesLabels.add(buySell);
    finalPricesLay.add(finalPricesLabels);
    finalPricesLay.add(Box.createVerticalStrut(10));
    finalPricesLay.add(weeklySelect);
    finalPricesLay.add(dailySelect);
    finalPricesLay.add(priceUScroll);
    dataOut.setLeftComponent(finalPricesLay);
    mainConsoleBackdrop.setTopComponent(graphs);
    mainConsoleBackdrop.setBottomComponent(dataOut);
    getContentPane().add(mainConsoleBackdrop);
    getContentPane().add(mainSelect, BorderLayout.NORTH);
    //visibility
    // CSEFrame.setVisible(true);
    //return(CSEFrame);
    public void actionPerformed(ActionEvent e)
    getMonth();
    inputS = e.getActionCommand();
    FileReader newRead = null;
    try {
    newRead = new FileReader(monthS +"-" +dayS +"-" +yearS +"/" +inputS +".dat");
    proceed = true;
    catch(FileNotFoundException f)
    System.out.println("File not found");
    proceed = false;
    if(proceed)
    BufferedReader bufferedReader = new BufferedReader(newRead);
    scanner = new Scanner(bufferedReader);
    scanner.useDelimiter("\n");
    //starts daily analysis
    getPrice(scanner);
    //starts weekly analysis
    weekly(inputS);
    public void itemStateChanged(ItemEvent e)
    if(weeklySelect.isSelected())
    priceUpdateWeekly.setText("");
    finalPricesLay.remove(priceUScroll);
    finalPricesLay.add(priceUScrollW);
    finalPrices.updateUI();
    else
    priceUpdate.setText("");
    finalPricesLay.remove(priceUScrollW);
    finalPricesLay.add(priceUScroll);
    finalPrices.updateUI();
    public void weekly(String inputS)
    weekly = true;
    for(int x = 0; x >< 7; x++)
    dateToUse(month, day, year, (x+1));
    try
    FileReader weeklySource = new FileReader(monthS +"-" +dayS +"-" +year +"/" +inputS +".dat");
    BufferedReader weeklyBuffer = new BufferedReader(weeklySource);
    week[x] = new Scanner(weeklyBuffer);
    week[x].useDelimiter("\n");
    getPrice(week[x]);
    catch(FileNotFoundException f)
    JOptionPane.showMessageDialog(this, "No such weekly files- going back;" +(x+1) +"days");
    weekly = false;
    dateReset();
    public void getPrice(Scanner scanner)
    while(scanner.hasNextLine())
    //puts into string the next scan token
    String s = scanner.next();
    //takes the scan toke above and puts it into an editable enviroment
    String [] data = s.split("\\s");
    for(position = 0; position < data.length; position++)
    //Scanner test to make sure loop can finish, otherwise "no such line" error
    if(scanner.hasNextLine()==false)
    scanner.close();
    break;
    /*Starts data orignazation by reading from each perspective field
    * 1 = day
    * 2 = day of month
    * 3 = month
    * 4 = year
    if(position == 0 && weekly == false)
    String dayFromFile = data[position];
    int dayNum = Integer.parseInt(dayFromFile);
    priceUpdate.append(days[dayNum-1] +" ");
    else if(position == 1 && weekly == false )
    priceUpdate.append(data[position] + "/");
    else if(position == 2 && weekly == false)
    priceUpdate.append(data[position] + "/");
    else if(position == 3 && weekly == false)
    priceUpdate.append(data[position] +"\n");
    //if it is in [buy] area, it prints and computes
    else if(position == 7)
    //obtains string for buy price and stores it, then prints it
    String buy = data[position];
    if(weekly == false)
    priceUpdate.append("Buy: " +buy +"\n" );
    //converts buy to string
    currentBuyPrice = Integer.parseInt(buy);
    //eliminates problems caused by no data from server- makes the price 0
    if(currentBuyPrice < 0)
    currentBuyPrice = 0;
    //if it is greater it adds
    if(currentBuyPrice > buyPrice)
    buyPrice += currentBuyPrice;
    //if it is equal [there is no change] then it does nothing
    if(currentBuyPrice == buyPrice)
    buyPrice +=0;
    //if there is a drop, it subtracts
    else
    buyPrice -= currentBuyPrice;
    //if it is in [sell] area, it prints, and resets the position to zero because line is over
    else if(position == 8)
    //puts sell data into string and prints it
    String sell = data[position];
    if(weekly == false)
    priceUpdate.append("Sell: " + sell +"\n");
    //turns sell data into int.
    currentSellPrice = Integer.valueOf(sell).intValue();;
    //gets rid of problems caused by no data on server side- makes it 0
    if(currentSellPrice < 0)
    currentSellPrice = 0;
    //adds if there is an increase
    if(currentSellPrice > sellPrice)
    sellPrice += currentSellPrice;
    //does nothing if it is the same
    if(currentSellPrice == sellPrice)
    sellPrice +=0;
    //subtracts if there is drop
    else
    sellPrice -= currentSellPrice;
    //further protection against "No such line" and moves it down
    if(scanner.hasNextLine() == true)
    scanner.nextLine();
    //if scanner is finished, prints out all lines
    if(scanner.hasNextLine() == false && weekly == false)
    finalBuy.setText("Net Buy Price Change: "+buyPrice);
    finalSell.setText("Net Sell Price Change: " +sellPrice);
    buyPrice = 0;
    sellPrice = 0;
    position = data.length;
    else if(scanner.hasNextLine() == false && weekly == true)
    priceUpdateWeekly.append("\n" +weekPos[dayOfWeek] +" day of the week ended with; \nBuy Price;" +buyPrice +"\nSell Price;" +sellPrice);
    buyPrice = 0;
    sellPrice = 0;
    position = data.length;
    dayOfWeek++;
    if(dayOfWeek > 6)
    dayOfWeek = 0;
    public void getMonth()
    for(int x=0; x < monthCheck.length; x++)
    if(month == monthCheck[x])
    monthS = (x+1);
    x = monthCheck.length;
    public void dateToUse(int month, int day, int year, int increment)
    //set day of source
    dayS = (day - increment);
    //if day of source is less then O then we have moved to another month
    if(dayS <= 0)
    //checks the difference between how much we have incremented and the day we have started; this tells us how far into the new month we are
    int incrementDay = increment - day;
    //decrements month
    monthS--;
    //if month is less then zero, then we have moved into another year and month has become 12
    if(monthS <= 0)
    yearS--;
    monthS = 12;
    //the following looks at the current month and if it goes below it assigns the day to the proper ammount of days of the month before minus the days into the month
    if(month == 3)
    dayS = 28 - incrementDay;
    else if(month == 5 || month == 7)
    dayS = 29 - incrementDay;
    else if(month == 2 || month == 4 || month == 6 || month == 9 || month == 11)
    dayS = 31 - incrementDay;
    else
    dayS = 30 - incrementDay;
    //resets the source date to the current date once data from the week has been reached
    public void dateReset()
    dayS = day;
    monthS = month;
    yearS = year;
    public void init()
    //JFrame frame = new CSEFrameSet();
    // this.setContentPane(CSEFrameSet());
    CSE aCSE = new CSE();
    public static void main(String [] args)
    CSE cs = new CSE();
    }Message was edited by:
    Cybergasm

  • GridBagLayout: JInternalFrames and internal JDesktopPanes?

    What I want:
    A JToolbar a the top of my main JFrame and a JPanel (status bar) at the bottom of my frame that stretches/shrinks with the screen.
    AND JInternalFrames in the center area (the number is arbitrary and the position is -- for now -- arbitrary). These frames are NOT effected by any resizing of the main JFrame window.
    My problem:
    With all the components added to the JFrame, the JToolbar and JPanel are placed fine, but the JInternalFrames won't allow me to resize them -- i.e., when I drag the iframe(s) to a new size, not only do they revert back to the original size, but sometimes the frame will reposition itself within the frame altogether!! And even sometimes a graphic glitch will occur and suddenly two instances of my iframe(s) will appear (only one will actually be functional)! Plus, when I try to iconify one of the iframes, its desktopicon moves to the absolute bottom of the JFrame, and shifts my JPanel on top of it!
    I tried adding an internal JPanel to try to isolate my inner iframes from the nasty GB's effects and to try to make an, but it seems like the parent GridBagLayout still had an effect on the JPanel's contents.
    Is there a way to:
    1) allow the JInternalFrames to freely resize, and
    2) place an "internal JDesktopPane" so that when I iconify iframes, the desktopIcon appears above my JPanel status bar?
    Thank you for any help!
    Paul

    Here is some code (I don't recommend using GridBagLayout's, it's often much easier and flexible to use nested containers).
    JDesktopPane desktopPane = new JDesktopPane();
    JPanel toolbarContainer = new JPanel(new BorderLayout());
    toolbarContainer.add(myToolBar, BorderLayout.NORTH);
    toolbarContainer.add(desktopPane, BorderLayout.CENTER);
    JPanel main = new JPanel(new BorderLayout());
    main.add(toolbarContainer, BorderLayout.CENTER);
    main.add(myStatusBar, BorderLayout.SOUTH);

  • InternalFrame.setNorthPane(null) and JDesktopPane outline drag mode

    package components;
    import javax.swing.JDesktopPane;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JMenuBar;
    import javax.swing.JFrame;
    import javax.swing.KeyStroke;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.plaf.basic.BasicInternalFrameUI;
    * InternalFrameDemo.java requires:
    *   MyInternalFrame.java
    public class InternalFrameDemo extends JFrame
                                   implements ActionListener {
        JDesktopPane desktop;
        Point mouseCoord, windowCoord = new Point();
        public InternalFrameDemo() {
            super("InternalFrameDemo");
            //Make the big window be indented 50 pixels from each edge
            //of the screen.
            int inset = 50;
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setBounds(inset, inset,
                      screenSize.width  - inset*2,
                      screenSize.height - inset*2);
            //Set up the GUI.
            desktop = new JDesktopPane(); //a specialized layered pane
            createFrame(); //create first "window"
            setContentPane(desktop);
            setJMenuBar(createMenuBar());
            //Make dragging a little faster but perhaps uglier.
            desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
        protected JMenuBar createMenuBar() {
            JMenuBar menuBar = new JMenuBar();
            //Set up the lone menu.
            JMenu menu = new JMenu("Document");
            menu.setMnemonic(KeyEvent.VK_D);
            menuBar.add(menu);
            //Set up the first menu item.
            JMenuItem menuItem = new JMenuItem("New");
            menuItem.setMnemonic(KeyEvent.VK_N);
            menuItem.setAccelerator(KeyStroke.getKeyStroke(
                    KeyEvent.VK_N, ActionEvent.ALT_MASK));
            menuItem.setActionCommand("new");
            menuItem.addActionListener(this);
            menu.add(menuItem);
            //Set up the second menu item.
            menuItem = new JMenuItem("Quit");
            menuItem.setMnemonic(KeyEvent.VK_Q);
            menuItem.setAccelerator(KeyStroke.getKeyStroke(
                    KeyEvent.VK_Q, ActionEvent.ALT_MASK));
            menuItem.setActionCommand("quit");
            menuItem.addActionListener(this);
            menu.add(menuItem);
            return menuBar;
        //React to menu selections.
        public void actionPerformed(ActionEvent e) {
            if ("new".equals(e.getActionCommand())) { //new
                createFrame();
            } else { //quit
                quit();
        //Create a new internal frame.
        protected void createFrame() {
            final MyInternalFrame frame = new MyInternalFrame();
            ((BasicInternalFrameUI) frame.getUI()).setNorthPane(null);   
            frame.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));   
            frame.addMouseMotionListener(new MouseMotionAdapter() {
                public void mouseDragged(MouseEvent e) {  
                    isMouse2Move(frame, e);               
            frame.addMouseListener(new MouseAdapter() {          
                public void mousePressed(MouseEvent e) {                                                 
                    setWindowDragPoint(e);              
            frame.setVisible(true); //necessary as of 1.3
            desktop.add(frame);
            try {
                frame.setSelected(true);
            } catch (java.beans.PropertyVetoException e) {}
        private void isMouse2Move(Component frame, MouseEvent e) {
            int cur_type = frame.getCursor().getType();   
            if (cur_type >= Cursor.DEFAULT_CURSOR) {
                if (cur_type == Cursor.MOVE_CURSOR) {
                    moveWindow(frame, e);                       
        private void moveWindow(Component frame, MouseEvent e) {
            int deltaX, deltaY;
            Point newMouseCoord = e.getPoint();
            deltaX = (int) (newMouseCoord.getX() - mouseCoord.getX());
            deltaY = (int) (newMouseCoord.getY() - mouseCoord.getY());
            frame.getLocation(windowCoord);
            windowCoord.translate(deltaX, deltaY);
            frame.setLocation(windowCoord);
        private void setWindowDragPoint(MouseEvent e) {
            mouseCoord = e.getPoint();
        //Quit the application.
        protected void quit() {
            System.exit(0);
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            InternalFrameDemo frame = new InternalFrameDemo();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Display the window.
            frame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    package components;
    import javax.swing.JInternalFrame;
    import java.awt.event.*;
    import java.awt.*;
    /* Used by InternalFrameDemo.java. */
    public class MyInternalFrame extends JInternalFrame {
        static int openFrameCount = 0;
        static final int xOffset = 30, yOffset = 30;
        public MyInternalFrame() {
            super("Document #" + (++openFrameCount),
                  true, //resizable
                  true, //closable
                  true, //maximizable
                  true);//iconifiable
            //...Create the GUI and put it in the window...
            //...Then set the window size or call pack...
            setSize(300,300);
            //Set the window's location.
            setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
    }how to move frame (JDesktopPane) <desktop> can not enable drag outline mode..
    help me please!
    thank you.

    yes i want all the decorations.Then I have no idea what you are tying to do. Why are you getting rid of the title bar?
    Dragging is supported automatically by clicking on and then dragging the title bar. If you want to customize the behaviour then you would need to look at the UI. Good luck.

  • Same size of a JPanel & a JDesktopPane

    HI, can someone please tell how to set the same size of JPanel and of JDesktopPane that are in the same JFrame?, I've tried setting the size of the JPanel but when I run it the JPanel is reduced. Here is the code:
    import java.awt.*;
    import javax.swing.*;
    public class Ventana extends JFrame{
        JDesktopPane desktop;
        public Ventana (String title){
            super(title);
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            int maxX = screenSize.width - 400;
            int maxY = screenSize.height - 400;
            setPreferredSize(new Dimension(maxX, maxY));
            JPanel desktopPane = new JPanel();
            desktopPane.setLayout(new BoxLayout(desktopPane, BoxLayout.Y_AXIS));
            JPanel panelBotones = new JPanel();
            panelBotones.setSize(maxX, maxY/2);
            JButton aceptar = new JButton("Aceptar");
            panelBotones.add(aceptar, BorderLayout.PAGE_END);
            desktopPane.add(panelBotones);
            JSeparator sep = new JSeparator();
            desktopPane.add(sep);
            desktop = new JDesktopPane();
            desktop.setSize(maxX, maxY/2);
            JInternalFrame jif = new JInternalFrame("JIF", true, true, true, true);
            jif.setSize(new Dimension(maxX-9, maxY-10));
            desktop.add(jif);
            jif.setVisible(true);
            desktopPane.add(desktop);
            setContentPane(desktopPane);
            desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
            pack();
        public static void createAndShowGUI(){
            try{
                 // Set System L&F
                 JFrame.setDefaultLookAndFeelDecorated(true);
                 JDialog.setDefaultLookAndFeelDecorated(true);
                 System.setProperty("sun.awt.noerasebackground", "true");
                //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            catch (ClassNotFoundException e) {
               // handle exception
            catch (Exception e) {
                try{
                    UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
                }catch(Exception f) {
            Ventana miVentana = new Ventana("Ventanita");
            miVentana.setLocationRelativeTo(null);
            miVentana.setVisible(true);
        public static void main(String [] args){
            java.awt.EventQueue.invokeLater(new Runnable(){
                public void run(){
                    createAndShowGUI();
    }

    Never use setSize() when using a layout manager. Use setPreferredSize (and sometimes setMinimumSize and setMaximumSize).
    If you want components to be the same size then just use a GridLayout. Of course a GridLayout will just ignore the preferred size and allocate all the space available between the two components.
    Edited by: camickr on Jun 27, 2009 11:58 PM

  • Problem in Painting in JDesktopPane

    Hi
    Here is the code for my class:
    public class DiagramPane extends JDesktopPane{
    public DiagramPane() {
    setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    public void paint(Graphics g){
    super.paint(g);
    int cmpCount=getComponentCount();
    if(cmpCount>1){
    for(int i=0;i<cmpCount-1;i++){
    Component cmp1=getComponent(i);
    Component cmp2=getComponent(i+1);
    g.drawLine(cmp1.getX(),cmp1.getY(),cmp2.getX(),cmp2.getY());
    public static void main(String[] s){
    JFrame f=new JFrame();
    DiagramPane dgrPane= new DiagramPane();
    JScrollPane scr=new JScrollPane(dgrPane);
    JInternalFrame lst1=new JInternalFrame("Frame1");
    JInternalFrame lst2=new JInternalFrame("Frame2");
    lst1.setBounds(150,150,100,100);
    lst2.setBounds(300,300,100,100);
    lst1.show();
    lst2.show();
    f.getContentPane().add(scr);
    dgrPane.add(lst1);
    dgrPane.add(lst2);
    f.setSize(400,400);
    f.show();
    Run this code and try to move any of the two InternalFrames. The lines need to be repainted accurately but this doesn't happen. This happens due to background filling of dirty region in JLayeredPane paint method. Can anyone tell me, what I should do so as to make these lines repaint properly. Lines are not in dirty region.
    Thanks in advance.
    Anil.

    You need your own DesktopManager that triggers a repaint after dragging ends, like:
    class MyDesktopManager extends DefaultDesktopManager {
    public void endDraggingFrame(JComponent comp) {
         super.endDraggingFrame(comp);
         repaint();
    then use it in your custom DesktopPane
    public DiagramPane() {
    setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    setDesktopManager(new MyDesktopManager());
    Greetings
    Jeanette

  • Problem regarding JDesktopPane

    Hello, after seeing a Demo of InternalFrames from java tutorials, I have a idea to "replace" the InternalFrames with JLabels ( Dragging JLabels around inside a JDesktopPane )
    This is what i did :
    //open class, imports and other variables
         //declare as global variable
         JDesktopPane desktop;
         //main method (not shown)
         public TempFrame4(){
              Container contentPane;
              //creates a new pane
              desktop=new JDesktopPane();
              //set layout to flowlayout
              desktop.setLayout(new FlowLayout());
              //i do not have any idea what this mean
              desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
              //add the desktoppane to Container
              setContentPane(desktop);
              //other JComponents (not shown)
              ImageIcon image = new ImageIcon(getClass().getResource("/middle.gif"));
              JLabel lb=new JLabel(image);
              //adds label to JDesktopPane
              desktop.add(lb);
         } // constructor
    } // classHowever the label is non-draggable. Does anyone have any idea to how to make labels move around (draggable) inside a JDesktopPane? Am i missing out a lot of things? Sorry I just started Swing not long ago, so I am not efficient in this.
    Thanks!
    Message was edited by:
    TrAnScEnD3nT

    Probably using a null LayoutManager and some mouse listeners. People in the Swing forum would know. I can just tell you that FlowLayout will veto any attempt at moving or resizing.

  • Problems with JDesktopPane and JInternalFrame

    hello
    merry christmas .
    I have some strange problem with JDesktopPane .
    I have a frame with an splitpane and in right side of splitpane i have a JDesktopPane .
    I can easily add InternalFrames to this JDesktopPane but when there is two or more InternalFrame and when I have at least 2 internal frame(they are not minimized or in full screen mode or cover completely each other , just when overlap each other) my cpu usage go to 100% and as soon as i minimize one of them or go to full screen mode or drag out one of them problem resolves .
    I have not any extra code that cause this problem(i just overwrite the paint method in internal frames ) .
    Can you help me ?
    Thanks for your time

    Did you override paint() or paintComponent()? Generally you should override paintComponent() for Swing components.
    Regards,
    Tim

  • High CPU utilization with JDesktopPane.OUTLINE_DRAG_MODE

    Hello there,
    since I updated from Java SDK 1.4.0 to 1.4.1_01 I recognized a problem with MDI Java applications using a JDesktopPane with JInternalFrames. When the drag mode of the internal frames is set to OUTLINE_DRAG_MODE, which should have a better performance than the LIVE_DRAG_MODE the cpu utilization goes nearly up to 100% an the drag of the frame is quite slow.
    Does anybody else experience this problem?
    (The problem exists in the application I develop and also in the IDE Netbeans, I use for development)
    I am not sure if this is the right place for my problem, so if there is a better one to post it to, please tell me.
    Thanks
    R�diger

    Hi,
    I've also noticed this. It happens on Windows 2000 with 1.4.1, but not with version 1.4.0. Have you found a solution yet?
    Martin

  • Problem with JPanel and JDesktopPane

    Hi,
    I am having a problem with my app and I wonder if someone can see what I am doing wrong. I have a class that extends JFrame that holds a centered JPanel to draw on. There are also 3-4 other JInternalFrames that are in use.
    From what I have read to use JDesktopPane to organize the JInternalFrames, all you do is add the JInternalFrames to the JDesktopPane and setContentPane to be the JdesktopPane:
            Jpanel panel = new JPanel();
            JDesktopPane dm = new JDesktopPane();
            setContentPane(dm);
            dm.add(panel, BorderLayout.CENTER);
            dm.add(internalFrame1);
            dm.add(internalFrame2);
            dm.add(internalFrame3);But as soon as I add the panel to the JDesktopPane then my JPanel doesnt show up. As I had it before I was adding the panel to the content pane of the Jframe, and adding the JinternalFrames to the layeredPane like this:
            getContentPane().add(panel, BorderLayout.CENTER);
            lp = getLayeredPane();
            lp.add(internalFrame1);
            lp.add(internalFrame2);
            lp.add(internalFrame3);and this worked but the JInternalFrames behaved badly, not getting focus or moving to the top frame when clicked, which I guess is what JDesktopPane is supposed to do. But how do I get my original JPanel in my JFrame to show up when added to the JDesktopPanel?
    Am I missing something here?
    Thanks,
    Paul

    Thanks for your response. I will try that when I get home, although I will be surprised if that works because I am already using setPreferredSize() . It seemed to me that once a Jframe's content pane gets assigned to a JDesktopPane, then the JPanel no longer has anywhere to draw itself, as according to the Sun documentation, you can only add a JInternalFrame to a JDesktopPane.
    So I am thinking its not possible to have a JPanel as the content pane of a JFrame while having a JDesktopPane containing my JInternalFrames. Is this indeed the case?
    Thanks,
    Paul

  • Problem with JComboBox in a fixed JToolBar

    Hi,
    I've created a JComboBox in a JToolBar that contains all available fonts. When I click on the drop down arrow I only see the first font and a small part of the second. The JComboBox is dropped down in fact just as far as the border of the JToolbar. All the rest isn't visible to me; it seems that they are behind the other components of my JApplet. However, if I move the JToolBar from it's position (as it's a floatable component), there's no problem at all. So I'm wondering why I can't see everything when the JToolBar is docked.... Can anyone help me?
    Thanks in advance!!
    E_J

    it seems that they are behind the other components of my JApplet.Sounds like you are mixing AWT components with your Swing application. Make sure you are using JPanel, JButton ... and not Panel, Button....

  • JDesktopPane / JInternalFrames and Focus

    Hi,
    I am running into a confusing focus issue with JDesktopPane and JInternalFrames. The problem is that when I close a JInternalFrame that has the keyboard focus, the DesktopPane will activate another internal frame, but that internal frame doesn't get the keyboard focus. I thought that some of my extension classes might be screwing this up, but I can recreate the problem using just the basic JDesktopPane and JInternalFrame objects. Has anyone run into this before? If so, how have you gotten around it? I'm using JDK 1.5 and the default Metal LAF.
    I have included a little application that demonstrates the issue. Click on one frame, then click on another frame and close this frame. The first frame will be active (ie highlighted), but it doesn't own the keyboard focus. Acutally the first frame gains the focus and then immediately looses the focus.
    Thanks for any help,
    -Yeath
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class DesktopTest extends JFrame
       private JDesktopPane desktop_pane;
       private int number;
       public DesktopTest()
          super( "DesktopTest Application" );
          this.desktop_pane = new JDesktopPane();
          this.number = 0;
          this.getContentPane().setLayout( new BorderLayout() );
          this.getContentPane().add( this.desktop_pane, BorderLayout.CENTER );
          JMenuBar menu_bar = new JMenuBar();
          JMenu file_menu = new JMenu( "File" );
          file_menu.add( new AbstractAction( "New Frame", null )
             public void actionPerformed( ActionEvent e )
                newFrame();
          menu_bar.add( file_menu );
          this.setJMenuBar( menu_bar );
          for( int i = 0; i < 4; i++ )
             newFrame();
       private void newFrame()
          final JInternalFrame jif = new JInternalFrame( "Frame " + Integer.toString( number + 1 ), true, true, true );
          jif.getContentPane().setLayout( new BorderLayout() );
          JTextField jtf = new JTextField();
          jif.getContentPane().add( jtf );
          jif.setBounds( number * 30, number * 30, 150, 100 );
          jtf.addFocusListener( new FocusListener()
             public void focusGained( FocusEvent e )
                System.out.println( jif.getTitle() + " has gained the focus" );
             public void focusLost( FocusEvent e )
                System.out.println( jif.getTitle() + " has lost the focus" );
          this.desktop_pane.add( jif );
          jif.setVisible( true );
          this.number++;
       public static void main( String[] args )
          DesktopTest desktop = new DesktopTest();
          desktop.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          desktop.setSize( 800, 800 );
          desktop.setVisible( true );
    }

    Thanks for the replies,
    This sounds very much like the bug that has already been reported. But the work around doesn't seem to solve the problem. I catch the internalFrameClosed() event, and have the newly selected frame request the keyboard focus. But still I run into the situation where the frame gets the focus and immediately looses it again. If you look at the debug statements when executing the app, you'll see what i mean.
    Here is my updated newFrame function
    private void newFrame()
       final JInternalFrame jif = new JInternalFrame( "Frame " + Integer.toString( number + 1 ), true, true, true, true );
       jif.getContentPane().setLayout( new BorderLayout() );
       final JTextField jtf = new JTextField();
       jif.getContentPane().add( jtf );
       jif.setBounds( number * 30, number * 30, 150, 100 );
       jif.addInternalFrameListener( new InternalFrameAdapter()
          public void internalFrameActivated( InternalFrameEvent e )
             jtf.requestFocusInWindow();
          public void internalFrameClosed( InternalFrameEvent e )
             JInternalFrame selected = desktop_pane.getSelectedFrame();
             if( selected != null )
                selected.requestFocus();
       jtf.addFocusListener( new FocusListener()
          public void focusGained( FocusEvent e )
             System.out.println( jif.getTitle() + " has gained the focus" );
          public void focusLost( FocusEvent e )
             System.out.println( jif.getTitle() + " has lost the focus" );
       this.desktop_pane.add( jif );
       jif.setVisible( true );
       this.number++;
    }When I run this, and close a frame, I get the following debug output: It is as if nothing owns the keyboard focus after closing a frame.
    Frame 2 has lost the focus
    Frame 1 has gained the focus
    Frame 1 has lost the focusThanks for your help,
    -Yeath

  • How can I use JDesktopPane for storing components?

    Hi there!
    I want to write an app which uses JNI, but I need to store widgets into the JDesktopPane , so that this Pane is always visible, not minimazable and has no decoration.
    Is this possible at all, because as far as I know .add(Component c) only adds new JInternalFrames?
    Or is this possible with an JInternal Frame to use all the space, being always in background and to have no Windows-Decorations (above the JInternal Frame)
    I hope you can help my,thanks for reading!
    Mfg Clemens

    Why do you need to use a JDesktopPane? If all you want is a pane with components on (no menu bar, title bar etc) then you can use a JWindow.
    N35Sy

  • Urgent ! How to add multiple JToolBars in a single JFrame

    How to implement multiple JToolBars in a single JFrame
    or what is the concept behind floating toolBars.If anybody can help me ,Thisis very urgent

    If you insist on multiple toolbars, use the following code:
    JToolBar tb1 = new JToolBar();
    //add stuff
    JToolBar tb2 = new JToolBar();
    //add stuff
    //put the toolbars on the top of the window
    JPanel toolbars = new JPanel(new BorderLayout());
    toolbars.add(tb1, BorderLayout.NORTH);
    toolbars.add(tb2, BorderLayout.CENTER);
    getContentPane().add(toolbars, BorderLayout.NORTH);Stephen

  • How can i change the background color of a visible JDesktopPane

    I tried this things but nothing happened ->
    getDesktopPane().setBackground(color);
    list = Tool.findComponent(getDesktopPane(), JPanel.class);
    for (int i = 0; i < list.size(); i++)
    list.get(i).setBackground(color);
    getMainFrame().getContentPane().setBackground(color);
    peter
    "No trees were destroyed in the sending of this message. However,
    a large number of electrons were terribly inconvenienced."

    I'm not sure if this is anything close to what you are looking for, and if not, oh well. No harm done.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Random;
    import javax.swing.JButton;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JPanel;
    class InternalFrameTest extends JPanel
        private JDesktopPane desktop = new JDesktopPane();
        private JInternalFrame internalFrame = new JInternalFrame("Foobars Rule!");
        private Random random = new Random();
        public InternalFrameTest()
            setPreferredSize(new Dimension(400, 400));
            setLayout(new BorderLayout());
            add(desktop);
            internalFrame.setSize(new Dimension(200, 200));
            JButton changeColorBtn = new JButton("Change Color");
            changeColorBtn.addActionListener(new ActionListener()
                @Override
                public void actionPerformed(ActionEvent e)
                    desktop.setBackground(new Color(
                            random.nextInt(256),
                            random.nextInt(256),
                            random.nextInt(256)));
            JPanel buttonPanel = new JPanel();
            buttonPanel.add(changeColorBtn);
            internalFrame.add(buttonPanel);
            internalFrame.setVisible(true);
            desktop.add(internalFrame);
            internalFrame.setLocation(30, 30);
        private static void createAndShowUI()
            JFrame frame = new JFrame("InternalFrameTest");
            frame.getContentPane().add(new InternalFrameTest());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }

Maybe you are looking for

  • Idoc to Multiple file scenario

    Hi Experts, My scenario is IDOC to Multiple files.. IDOC will be triggered from the ECC system and i have three differient structures and need to drop those 3 files in the ftp server at the target system. Here we can use multimapping for such scenari

  • Issue regarding supported platforms manual for BO XI 3.1 sp2

    In supported platforms manual for BO XI 3.1 sp2 windows there is a note on page 7 for specific patch level for OAS 10gR3 u201CPlease see release notes on the minimum version supported for Dashboard and Analytics.u201D We try to find on release notes

  • Creating a print template

    I am considering purchasing Photoshop elements but have one problem.  I like to print photo album sheets from home on 8.5x11" paper in portrat orientation with about 9 dfferent photos per sheet.  I can't find any way to resize/reorient the photobook

  • Where is HTML help for uploading projects or where can i see Pods ??

    Hello Everyone, I am new to Robo Help. I have successfully installed Robo Help Server 8 in my PC. After i type http://<servername:port>/robohelp/admin I am able to view tha admin page. From there I am able to successfully able to login to the Admin M

  • Sharing collections

    why isn't it possible to export collections (to google maps/earth/whatever) or share them with other nokia users? i do not mean sharing single POIs, i know that is possible. i mean sharing complete collections. N8-00