Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Get JPrintPreviewDialog for button response

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Get JPrintPreviewDialog for button response

    I am trying to program a GUI for my own print preview dailog. The Frame just opens a dialog and passes a Image object to it.

    public class JPrintPreviewDialog extends JDialog{
     
        public JPrintPreviewDialog(JFrame owner, Image view) {
            super(owner, "Print preview dialog.");
     
            Container contentPane = new Container();
            contentPane = this.getContentPane();
     
            JPanel backgroundPanel = new JPanel();
            backgroundPanel.setBackground(Color.GRAY);
            contentPane.add(backgroundPanel, BorderLayout.CENTER);
     
            m_page = new JPagePanel(view);
            backgroundPanel.add(m_page, new GridBagLayout());
     
            JMenuPanel menuPanel = new JMenuPanel();
            contentPane.add(menuPanel, BorderLayout.SOUTH);
     
            this.setSize(new Dimension(640, 500));
     
            this.setLocationRelativeTo(null);
            this.setVisible(true);
            this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        }
     
        private JPagePanel m_page;
    }

    it has a grey background panel backgroundPanel, white panel that is the printer paper, and panel that is the southern borderlayout menu that contains a print button.

    How can i fire a print event from the button that is on the JMenuPanel? The JFrame
    implements printable.


  2. #2
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Get JPrintPreviewDialog for button response

    import java.awt.event.WindowEvent;
    import javax.swing.SwingUtilities;
     
    /**
     *
     * @author Gebruiker
     */
    public class JMenuPanel extends javax.swing.JPanel {
     
        /** Creates new form JMenuPanel */
        public JMenuPanel() {
            initComponents();
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            printButton = new javax.swing.JButton();
            cancelButton = new javax.swing.JButton();
     
            setBackground(new java.awt.Color(51, 153, 255));
            setPreferredSize(new java.awt.Dimension(546, 41));
     
            printButton.setText("Print");
            printButton.setToolTipText("Start printing.");
     
            cancelButton.setText("Cancel");
            cancelButton.setToolTipText("Cancel print preview.");
            cancelButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    cancelButtonActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(397, Short.MAX_VALUE)
                    .addComponent(printButton)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(cancelButton)
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cancelButton)
                        .addComponent(printButton))
                    .addContainerGap())
            );
        }// </editor-fold>                        
     
        private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
            SwingUtilities.windowForComponent(this).dispose();
        }                                            
     
     
        // Variables declaration - do not modify                     
        private javax.swing.JButton cancelButton;
        private javax.swing.JButton printButton;
        // End of variables declaration                   
     
    }

    more code thanks in advance.

Similar Threads

  1. How Manipulate HTTP response?
    By nikos in forum Java Networking
    Replies: 1
    Last Post: October 7th, 2010, 12:22 PM
  2. empty response received
    By grashmi13 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 16th, 2010, 05:30 PM
  3. Not able to receive SOAP response
    By abhisekh in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 12th, 2010, 07:20 AM
  4. Replies: 6
    Last Post: April 14th, 2009, 08:02 AM
  5. [SOLVED] Java for loop problem and out put is not coming
    By thewonderdude in forum Loops & Control Statements
    Replies: 9
    Last Post: March 15th, 2009, 02:31 PM