the real moins moins | allez hop, un bidule qui va à la ligne si necessaire
(super bourrin hein, mais bon voilà quoi)
Code :
- public static Image getMessageImage(String title, Color color) {
- Image img = new BufferedImage(IMAGE_SIZE_X, IMAGE_SIZE_Y, BufferedImage.TYPE_BYTE_INDEXED);
- Graphics2D graphics = (Graphics2D) img.getGraphics();
- graphics.setClip(0, 0, IMAGE_SIZE_X, IMAGE_SIZE_Y);
- // fill the background with white
- graphics.setColor(Color.white);
- graphics.fillRect(0, 0, IMAGE_SIZE_X, IMAGE_SIZE_X);
- // prints title text in <color>
- graphics.setColor(color);
- graphics.setFont(new Font("Helvetica", Font.BOLD, 14));
- int lineHeight = graphics.getFontMetrics().getHeight()+5;
- int maxLineSize = IMAGE_SIZE_X-20;
- StringTokenizer st = new StringTokenizer(title, " \n\r\t\f", true);
- StringBuffer currentLine = new StringBuffer();
- String nextEl = new String();
- int nbrLines = 0;
- while (st.hasMoreElements()) {
- currentLine = new StringBuffer();
- nbrLines++;
- while (graphics.getFontMetrics().stringWidth(currentLine.toString()+nextEl) <= maxLineSize && st.hasMoreElements()) {
- currentLine.append(nextEl);
- nextEl = (String) st.nextElement();
- }
- graphics.drawString(currentLine.toString(), 10, (nbrLines*lineHeight));
- }
- graphics.drawString(currentLine.toString()+nextEl, 10, (nbrLines*lineHeight));
- return img;
- }
|
---------------
Hey toi, tu veux acheter des minifigurines Lego, non ?
|