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

avec Java Discussion :

Comment imprimer un paragraphe on utilisant un JLabel ?


Sujet :

avec Java

  1. #1
    Membre à l'essai
    Inscrit en
    Juillet 2009
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 28
    Points : 24
    Points
    24
    Par défaut Comment imprimer un paragraphe on utilisant un JLabel ?
    Bonjour

    Voila je dois imprimé un bon de reçu alors je me suis dis que j'utiliserai un JLabel en lui ajoutant la fonction print mais le vraie probleme c que j'arrive pas a ecrire un contenu de texte comme un paragraphe dans le JLabel utliser !

    par example :

    JLabel ecran = new JLabel();

    ecran = new JLabel(
    "************
    ************
    ************");

    voila ce que j'éssaye de vous expliquer c'est que je veux imprimer un paragraphe et pas une phrase!

    mais ca ne marche pas, quelqu'un aurai une idée a me proposer ?

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    299
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2009
    Messages : 299
    Points : 422
    Points
    422
    Par défaut
    Si tu arrives à faire un JPanel présenté comme tu le souhaites, j'avais trouvé cette class sur le net, qui marche pas mal du tout pour imprimer un Component :

    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
    import java.awt.*;
    import javax.swing.*;
    import java.awt.print.*;
     
    /** A simple utility class that lets you very simply print
     *  an arbitrary component. Just pass the component to the
     *  PrintUtilities.printComponent. The component you want to
     *  print doesn't need a print method and doesn't have to
     *  implement any interface or do anything special at all.
     *  <P>
     *  If you are going to be printing many times, it is marginally more 
     *  efficient to first do the following:
     *  <PRE>
     *    PrintUtilities printHelper = new PrintUtilities(theComponent);
     *  </PRE>
     *  then later do printHelper.print(). But this is a very tiny
     *  difference, so in most cases just do the simpler
     *  PrintUtilities.printComponent(componentToBePrinted).
     *
     *  7/99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
     *  May be freely used or adapted.
     */
     
    public class PrintUtilities implements Printable {
      private Component componentToBePrinted;
     
      public static void printComponent(Component c) {
        new PrintUtilities(c).print();
      }
     
      public PrintUtilities(Component componentToBePrinted) {
        this.componentToBePrinted = componentToBePrinted;
      }
     
      public void print() {
        PrinterJob printJob = PrinterJob.getPrinterJob();
        printJob.setPrintable(this);
        if (printJob.printDialog())
          try {
            printJob.print();
          } catch(PrinterException pe) {
            System.out.println("Error printing: " + pe);
          }
      }
     
      public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
        if (pageIndex > 0) {
          return(NO_SUCH_PAGE);
        } else {
          Graphics2D g2d = (Graphics2D)g;
          g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
          disableDoubleBuffering(componentToBePrinted);
          g2d.scale(0.7, 0.7);
          componentToBePrinted.paint(g);
          enableDoubleBuffering(componentToBePrinted);
          return(PAGE_EXISTS);
        }
      }
     
      /** The speed and quality of printing suffers dramatically if
       *  any of the containers have double buffering turned on.
       *  So this turns if off globally.
       *  @see enableDoubleBuffering
       */
      public static void disableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(false);
      }
     
      /** Re-enables double buffering globally. */
     
      public static void enableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(true);
      }
    }

Discussions similaires

  1. [VB.NET]Comment Imprimer une form
    Par bernard06 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 19/10/2011, 17h43
  2. [CR] Comment imprimer dans le bon ordre
    Par speed034 dans le forum SAP Crystal Reports
    Réponses: 5
    Dernier message: 18/05/2004, 11h11
  3. [Impression] Comment imprimer un .txt?
    Par Grosgrognon dans le forum API standards et tierces
    Réponses: 2
    Dernier message: 27/04/2004, 13h19
  4. Comment imprimer des tabulations ?
    Par Invité dans le forum C++Builder
    Réponses: 2
    Dernier message: 27/11/2002, 11h30
  5. Comment imprimer le contenu d'un TStringGrid
    Par scorpiwolf dans le forum C++Builder
    Réponses: 2
    Dernier message: 19/06/2002, 15h41

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