5 Replies - 275 Views - Last Post: 16 January 2013 - 12:34 PM Rate Topic: -----

#1 Randor  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 106
  • Joined: 12-October 10

opening new frames for printing

Posted 14 January 2013 - 07:45 AM

Hello all,

I have a list of "orders" in a java application and I want to be able to click on a button at each order and open a new pane that the user can print the order from, so I need to be able to have multiple frames open at one time.

I did this:

		JFrame window2 = new JFrame();
                 window2.setSize(500,500);
                 JPanel panel2 = new JPanel(new GridBagLayout());
                 panel2 = bov.build(orderNumber); //adds in the specific order
                JScrollPane scrollBar = new JScrollPane(panel2,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);               
                window2.add(scrollBar);
		window2.setVisible(true); 



which opens multiple windows, however; once you open a second window the first window goes blank, and so on, so even though it opens multiple windows only the last window open shows the order.

So my thought was that it must be because I am building multiple windows with the same object (window2)..

So I tried this:

//up in  the constructor
ArrayList FrameHold = new ArrayList();

                 //main function
		JFrame window2 = new JFrame();
                int CF = FrameHold.size();
                FrameHold.set(CF,window2);
                
                FrameHold.get(CF).setSize(500,500);
                JPanel panel2 = new JPanel(new GridBagLayout());
                panel2 = bov.build(); //adds in the specific order 
                JScrollPane scrollBar = new JScrollPane(panel2,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);               
                FrameHold.get(CF).add(scrollBar);
		FrameHold.get(CF).setVisible(true);  


however, I get this error:

cannot find symbol
method setSize(int,int);


can someone please help me on this,

Thank you very much

Is This A Good Question/Topic? 0
  • +

Replies To: opening new frames for printing

#2 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,531
  • Joined: 29-July 11

Re: opening new frames for printing

Posted 14 January 2013 - 07:56 AM

You can go the JInternalFrame route, or you can go what I would call the easy route and just create a method that returns a JFrame subclass and display that. I wouldn't play arounf with JOptionPane.

public JFrame getMessageFRame() {
JFrame frame = new JFrame(string title, String message) {
    {
        super(title);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(300,300);
        setVisible(true);
    }
   
    ///other components and functionality go here.
}

return frame;

}//end getMessageFrame();



Then just instantiate and show the frame.

As for your problem. My eyes gloss over while reading other peoples' code today, so I can't do it. Sorry. :)

This post has been edited by farrell2k: 14 January 2013 - 07:57 AM

Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: opening new frames for printing

Posted 15 January 2013 - 02:20 PM

Or you use generic (what you actually should do)

ArrayList<JFrame> FrameHold = new ArrayList<JFrame>();

or you cast what is returned by get to JFrame so you can apply setSize() to it

((JFrame) FrameHold.get(CF)).setSize(...
Was This Post Helpful? 1
  • +
  • -

#4 Randor  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 106
  • Joined: 12-October 10

Re: opening new frames for printing

Posted 16 January 2013 - 07:31 AM

Thank you for the replies, I went with the suggestion of PBL and did this:

Constructor:
    ArrayList<JFrame> FrameHold = new ArrayList<JFrame>();
    ArrayList<JScrollPane> PanelHold = new ArrayList<JScrollPane>();



                        int CF = FrameHold.size();
                        FrameHold.add(CF, new JFrame());
                        FrameHold.get(CF).setBounds(winx, winy, 500, 500);
                        winx = winx+40; winy = winy+40;
                        JPanel panel2 = new JPanel(new GridBagLayout());

                        panel2 = bov.build();

                        //Create a scrollbar using JScrollPane and add panel into it's viewport  
                        //Set vertical and horizontal scrollbar always show  
                        JScrollPane scrollBar = new JScrollPane(panel2,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                        PanelHold.add(CF, scrollBar);
                        FrameHold.get(CF).add(PanelHold.get(CF));
                        FrameHold.get(CF).setVisible(true);


in the bov.build() method is this:

        head.setBackground(Color.red);
        head.setOpaque(true);
        addComponent(head, 0,0, GridBagConstraints.NONE, 1, 0, 0,10,8,GridBagConstraints.NORTH);
        addComponent(new JSeparator(SwingConstants.HORIZONTAL), 0,1, GridBagConstraints.HORIZONTAL, 2, 2, 0,10,8,GridBagConstraints.NORTH);
        addComponent(BLImage, 0,2, GridBagConstraints.NONE, 2, 2, 0,10,2,GridBagConstraints.CENTER);
        addComponent(new JSeparator(SwingConstants.HORIZONTAL), 0,3, GridBagConstraints.HORIZONTAL, 10, 10, 0,10,8,GridBagConstraints.ABOVE_BASELINE);

        return cc;

the addComponent methods just build different items to show on the form.

The problem is that when i click on multiple windows to open only the last window opened keeps the contents of its window showing, every window under the last window opened goes blank, now if i move the top one and open a new window the new window and the old window both show, but as soon as I expand the older version, all the information goes away again..

I dont know if it is the coding or a flaw in Java or something? any ideas??
Was This Post Helpful? 0
  • +
  • -

#5 sk8ermeb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 111
  • Joined: 23-March 10

Re: opening new frames for printing

Posted 16 January 2013 - 10:49 AM

I don't know if this is good advice (someone more experienced may state otherwise) but I have often ran into similar issues with multiple frames. The way I have had to get around it so all frames function entirely separately as coded is to open each frame in its own thread, something like:

JFrame myFrame;

Thread t = new Thread(){
@Override
public void run(){openNewFrame();}
};
t.start();

public void openNewFrame(){
 myFrame = new JFrame();
}



But if you are not experienced with multi-threading this could be more of a headache than it is worth, since it is not strait forward to use resources between frames.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: opening new frames for printing

Posted 16 January 2013 - 12:34 PM

Why do you always overcomplicate things for nothing ?

Why getting arrayList size
add JFrame to it
retreive it (based on saved size) multiple time to modify it ?

Just create the JFrame
do what ever you have to do with it
then simply arrayList.add(frame)

and, when you add an Object to an ArrayList it does not vanish, you can still used it without getting it back from the ArrayList

   JFrame f = new JFrame();
   int fc = al.size();
   al.add(f);
   al.get(fc).setXXX();
   al.get(fc).setYYY();
   al.get(fc).setZZZ();

and

   JFrame f = new JFrame();
   al.add(f);
   f.setXXX();
   f.setYYY{);
   f.setZZZ();


are equivalent


Write your own inner class MyFrame that extends JFrame wich save in its instance variables the JScollPane and you will need only one ArrayList, from the removed MyFrame you'll be able to access the JScrollPane

This post has been edited by pbl: 16 January 2013 - 12:48 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1