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.
Code :
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.
Re: Get JPrintPreviewDialog for button response
Code :
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.