IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Agents de placement/Fenêtres Java Discussion :

Impression d'un Panneau


Sujet :

Agents de placement/Fenêtres Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    174
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 174
    Par défaut Impression d'un Panneau
    Bonjour,

    j'ai dessiné un panneau et j'ai voudrais l'imprimer mais puisque mon panneau s'etend j'aimerais qu'il soit imprimer sur plusieurs pages voila ma classe qui herite du JPanel :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    class MonDessin extends JPanel implements Printable,ActionListener{
     
    	int[] pageBreaks;
     
    	public int print(Graphics g, PageFormat pf, int pageIndex)
    			throws PrinterException {
     
    	        int lineHeight = 20;
     
    	        if (pageBreaks == null) {
    	            int linesPerPage = (int)(pf.getImageableHeight()/lineHeight);
    	            int numBreaks = (Table[0].size()-1)/linesPerPage;
    	            pageBreaks = new int[numBreaks];
    	            for (int b=0; b<numBreaks; b++) {
    	                pageBreaks[b] = (b+1)*linesPerPage; 
    	            }
    	        }
     
    	        if (pageIndex > pageBreaks.length) {
    	            return NO_SUCH_PAGE;
    	        }
     
     
    	        Graphics2D g2d = (Graphics2D)g;
    	        g2d.translate(pf.getImageableX(), pf.getImageableY());
     
     
    	        y=200;
    			         y1=20;y2=190;y3=180;y4=210;y5=230;y6=250;y7=205;y8=225;y9=245;y10=265;
    			  for(int i = 0; i<Table[0].size(); i++){
    	              g.drawString(String.valueOf(Table[0].get(i)),20,y);
    	              g.drawString(String.valueOf(Table[1].get(i)).substring(0, 13),75,y);
    	              g.drawString(String.valueOf(Table[2].get(i)),205,y);
    	              g.drawString(String.valueOf(Table[3].get(i)),240,y);
     
    	              g.drawString(String.valueOf(Table[0].get(i)),310,y);
    	              g.drawString(String.valueOf(Table[1].get(i)).substring(0, 13),365,y);
    	              g.drawString(String.valueOf(Table[2].get(i)),510,y);
    	              g.drawString(String.valueOf(Table[3].get(i)),530,y);
    	              y+=15;
    	              y1+=15;y2+=15;y3+=15;y4+=15;y5+=15;y6+=15;y7+=15;y8+=15;
    	              y9+=15;y10+=15;
    	       }
    			  y+=15;
    	          y1+=15;y2+=15;y3+=15;y4+=15;y5+=15;y6+=15;y7+=15;y8+=15;
    	          y9+=15;y10+=15;
    				g.drawRoundRect(20, 160, 270, y1, 8, 8);
    				g.drawRoundRect(310, 160, 270, y1, 8, 8);
     
    				g.drawLine(70, 160, 70, y3);
    				g.setFont(font1);
    				g.drawString("***.", 25, 175);
    				g.drawString("*******", 75, 175);
    				g.drawLine(200, 160, 200, y3);
    				g.drawString("Qté", 205, 175);
    				g.drawLine(20, 185, 290, 185);
    				g.drawLine(230, 160, 230, y3);
    				g.drawString("***", 245, 175);
     
     
    				g.drawLine(360, 160, 360, y3);
    				g.drawString("***.", 315, 175);
    				g.drawString("******", 365, 175);
    				g.drawLine(500, 160, 500, y3);
    				g.drawString("****", 505, 175);
    				g.drawLine(530, 160, 530, y3);
    				g.drawString("***", 535, 175);
    				g.drawLine(310, 185, 580, 185);
     
    				g.setFont(font2);
    				g.drawString("****", 90, 30);
    				g.drawLine(30, 35, 280, 35);
    				g.drawString("****", 40, 50);
    				g.drawString("*****", 50, 70);
    				g.drawString("******", 110, 110);
     
     
    				g.drawString("*********", 390, 30);
    				g.drawLine(330, 35, 580, 35);
    				g.drawString("******", 340, 50);
    				g.drawString("*******", 350, 70);
    				g.drawString("*****", 410, 110);
     
    				g.setFont(font3);
    				g.drawString("******", 50, 90);
    				g.drawString("*******", 350, 90);
     
    				g.drawRoundRect(150, y2, 140, 80, 8, 8);
    				g.drawLine(150, y4, 290, y4);
    				g.drawLine(150, y5, 290, y5);
    				g.drawLine(150, y6, 290, y6);
    				g.drawString("***",155 ,y7);
    				g.drawString("***",155 ,y8);
    				g.drawString("***",155 ,y9);
    				g.drawString("****",155 ,y10);
     
    				g.drawRoundRect(440, y2, 140, 80, 8, 8);
    				g.drawLine(440, y4, 580, y4);
    				g.drawLine(440, y5, 580, y5);
    				g.drawLine(440, y6, 580, y6);
    				g.drawString("***",445 ,y7);
    				g.drawString("***",445 ,y8);
    				g.drawString("***",445 ,y9);
    				g.drawString("****",445 ,y10);
     
    		               g.drawString(Date_Bl, 160, 110); 
    		               g.drawString(Date_Bl, 460, 110);
     
    	        return PAGE_EXISTS;
    	}
     
     
    	public void actionPerformed(ActionEvent e) {
            PrinterJob job = PrinterJob.getPrinterJob();
            job.setPrintable(this);
            boolean ok = job.printDialog();
            if (ok) {
                try {
                     job.print();
                } catch (PrinterException ex) {
     
                }
            }
       }	
    }

    mon problème est que mon panneau s'imprime sur deux pages mais dans la deuxième page je reçoit un double de la première page non pas le continu de mon panneau, Comment je peux régler ce problème et merci.

  2. #2
    Membre chevronné Avatar de javaNavCha
    Homme Profil pro
    EKG Group
    Inscrit en
    Juillet 2009
    Messages
    311
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Tunisie

    Informations professionnelles :
    Activité : EKG Group
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2009
    Messages : 311
    Par défaut
    Salut
    Voici une classe que j'utilise pour imprimer mes JPanel
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
     
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridBagLayout;
    import java.awt.RenderingHints;
    import java.awt.print.PageFormat;
    import java.awt.print.Paper;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Vector;
     
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
     
    /**
     * @author mep
     *
     */
    public class MPanelPrinter
        implements Printable
    {
     
        public MPanelPrinter(JPanel panel)
        {
            documentTitle = "";
            this.panel = panel;
            initPrintablePanel();
        }
     
        public void initPrintablePanel()
        {
            showPrintZone = false;
            fitIntoPage = false;
            wrapComponent = false;
            printJob = PrinterJob.getPrinterJob();
            pageFormat = printJob.defaultPage();
            pageFormat.setOrientation(1);
        }
     
        public void setOrientation(int orientation)
        {
            pageFormat.setOrientation(orientation);
        }
     
        public void setPrintZoneVisible(boolean status)
        {
            showPrintZone = status;
        }
     
        public void setWrapComponent(boolean status)
        {
            wrapComponent = status;
        }
     
        public void setFitIntoPage(boolean status)
        {
            fitIntoPage = status;
        }
     
        public int getPageWidth()
        {
            return (int)pageFormat.getImageableWidth();
        }
     
        public double getMarginTop ()
        {
            return pageFormat.getImageableY();
        }
     
        public double getMarginLeft ()
        {
            return pageFormat.getImageableX();
        }
     
        public void setLRMargins(int margin)
        {
            Paper paper = pageFormat.getPaper();
            paper.setImageableArea(paper.getImageableX() , paper.getImageableY(), paper.getImageableWidth(), paper.getImageableHeight());
            pageFormat.setPaper(paper);
     
        }
     
        public void setTBMargins(int margin)
        {
            Paper paper = pageFormat.getPaper();
            paper.setImageableArea(paper.getImageableX(), paper.getImageableY() , paper.getImageableWidth(), paper.getImageableHeight() + (double)(margin / 2));
            pageFormat.setPaper(paper);
            System.out.println("marge = "+margin);
     
        }
     
        public void setDocumentTitle(String title)
        {
            documentTitle = title;
        }
     
        public int print(Graphics g, PageFormat pf, int pageIndex)
            throws PrinterException
        {
            Dimension tailleDoc = panel.getSize();
            double hauteurDocu = tailleDoc.getHeight();
            double hauteurPage = pf.getImageableHeight();
            double largeurDocu = tailleDoc.getWidth();
            double largeurPage = pf.getImageableWidth();
            int totalNumPages = (int)Math.ceil(hauteurDocu / hauteurPage);
            if(wrapComponent)
                totalNumPages = taillePages.size();
            else
            if(fitIntoPage)
                totalNumPages = 1;
            double scaleX = largeurPage / largeurDocu;
            double scaleY = hauteurPage / hauteurDocu;
            if(pageIndex >= totalNumPages)
                return 1;
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            g2d.translate(pf.getImageableX(), pf.getImageableY());
            if(fitIntoPage)
            {
                double ratio = Math.min(scaleX, scaleY);
                g2d.scale(ratio, ratio);
            } else
            if(wrapComponent)
            {
                if(pageIndex > 0)
                    g2d.translate(0.0D, -((Double)taillePages.get(pageIndex - 1)).doubleValue());
            } else
            {
                g2d.translate(0.0D, (double)(-pageIndex) * hauteurPage);
            }
            panel.paint(g2d);
            if(wrapComponent)
            {
                double hauteurBlanc = ((Double)taillePages.get(pageIndex)).doubleValue();
                g2d.setColor(Color.WHITE);
                g2d.fillRect(0, (int)hauteurBlanc, (int)largeurPage, (int)hauteurBlanc + (int)hauteurPage);
            }
            if(wrapComponent)
            {
                if(pageIndex > 0)
                    g2d.translate(0.0D, ((Double)taillePages.get(pageIndex - 1)).doubleValue());
            } else
            {
                g2d.translate(0.0D, (double)pageIndex * hauteurPage);
            }
            g2d.setColor(Color.BLACK);
            g2d.setFont(new Font("Verdanna", 2, 10));
            SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
    		String date0 = format.format(new Date());
     
     
            g2d.drawString( "Fiche XXX: Date d'impression : "+date0+"  ", 0, (int)pf.getImageableHeight() - 5);
            return 0;
        }
     
        public void print()
        {
            printJob.setPrintable(this, pageFormat);
            try
            {
                if(printJob.printDialog())
                {
                    if(wrapComponent)
                        calculatePages();
                    Paper paper = pageFormat.getPaper();
                    Paper save = pageFormat.getPaper();
                    paper.setImageableArea(paper.getImageableX(), paper.getImageableY(), paper.getWidth() - paper.getImageableX(), paper.getHeight() - paper.getImageableY());
                    pageFormat.setPaper(paper);
                    printJob.setPrintable(this, pageFormat);
                    printJob.print();
                    pageFormat.setPaper(save);
                }
            }
            catch(PrinterException pe)
            {
                System.out.println("Erreur lors de l'impression du document: " + toString());
            }
        }
     
        private void calculatePages()
        {
            taillePages = new Vector();
            double hauteurPage = pageFormat.getImageableHeight();
            double hauteurTotal = 0.0D;
            double hauteurCumul = 0.0D;
            for(int i = 0; i < panel.getComponentCount(); i++)
            {
                int gridBagInsets = 0;
                if(panel.getLayout() instanceof GridBagLayout)
                    gridBagInsets = ((GridBagLayout)panel.getLayout()).getConstraints(panel.getComponent(i)).insets.bottom + ((GridBagLayout)panel.getLayout()).getConstraints(panel.getComponent(i)).insets.top;
                double hauteurComponent = panel.getComponent(i).getSize().getHeight() + (double)gridBagInsets;
                if(hauteurComponent > hauteurPage)
                {
                    wrapComponent = false;
                    return;
                }
                hauteurTotal += hauteurComponent;
                if(hauteurTotal > hauteurPage)
                {
                    hauteurTotal -= hauteurComponent;
                    hauteurCumul += hauteurTotal;
                    taillePages.add(new Double(hauteurCumul));
                    hauteurTotal = hauteurComponent;
                }
            }
     
            hauteurCumul += hauteurTotal;
            taillePages.add(new Double(hauteurCumul));
        }
     
        private JPanel panel;
        private boolean showPrintZone;
        private boolean fitIntoPage;
        private boolean wrapComponent;
        private PageFormat pageFormat;
        private PrinterJob printJob;
        private Vector taillePages;
        private String documentTitle;
        public static final int PORTRAIT = 1;
        public static final int LANDSCAPE = 0;
    }
    Puis t'as qu'à passer ton JPanel
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    MPanelPrinter	X=new MPanelPrinter(Panneau);
    X.print();

  3. #3
    Membre confirmé
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    174
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 174
    Par défaut
    bonjour,

    cette classe me donne une impression de mon panneau sur une seule page et ce que je veux est l'impression sur deux pages a-tu un exemple qui peut le faire sur deux pages ?

    merci.

  4. #4
    Membre chevronné Avatar de javaNavCha
    Homme Profil pro
    EKG Group
    Inscrit en
    Juillet 2009
    Messages
    311
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Tunisie

    Informations professionnelles :
    Activité : EKG Group
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2009
    Messages : 311
    Par défaut
    Salut
    ce que je fais dans ce cas, c'est de rendre le JPanel en 2 JPanel... puis les imprimer.

  5. #5
    Membre confirmé
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    174
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 174
    Par défaut
    merci, pourrait-tu me donner un exemple.

  6. #6
    Membre confirmé
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    174
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 174
    Par défaut
    j'ai trouvé la réponse par là : L'impression en java.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. cacher panneau impression en court
    Par Renardo dans le forum IHM
    Réponses: 4
    Dernier message: 25/08/2008, 23h02
  2. message suite a impression et panneau de config
    Par itsmee dans le forum Windows Vista
    Réponses: 0
    Dernier message: 03/08/2007, 16h40
  3. [CR][VB6] Impression d'un état depuis VB
    Par sda dans le forum SDK
    Réponses: 3
    Dernier message: 06/02/2007, 18h27
  4. Impression d'image bmp
    Par Invité dans le forum Langage
    Réponses: 6
    Dernier message: 18/07/2002, 10h38
  5. Problème d'impression
    Par IngBen dans le forum C++Builder
    Réponses: 7
    Dernier message: 22/05/2002, 12h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo