Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6817653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:04:55+00:00 2026-05-26T21:04:55+00:00

I am trying to write a watermarking program with java , So I found

  • 0

I am trying to write a watermarking program with java , So I found this piece of code for the same.

I made my own adaptation for my purposes like so (Full src : https://gist.github.com/1373080/)

 /**
 *
 * This method  converts a multiline string into an ArrayList of Strings
 * Each item on the array list is a line of the string.
 * @param str A multiline string
 * @return An ArrayList of strings , a string per line of text
 * @see java.util.ArrayList
 */
private static ArrayList<String> convertStringToLineString(String str){
    ArrayList<String> string = new ArrayList<String>();
    String s = new String ();
    char [] ca = str.toCharArray();

    for(int i=0;i<ca.length;i++){
        if(ca[i] == '\n'){
            string.add(s);
            s = new String();
        }
        s += ca[i];
    }
    return string;
}

The string is drawn like so

    int x =(img.getIconWidth() - (int) rect.getWidth()) / 2,
    y =(img.getIconHeight() - (int) rect.getHeight()) / 2;

    ArrayList<String> watermarks = convertStringToLineString(watermark);
    for (String w : watermarks){
    g2d.drawString(w,x,y);
        y+=20;
    }

The problem I am facing is that a string like a calendar

 November 2011      
Su Mo Tu We Th Fr Sa  
       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   

which contains multiple lines does not get drawn properly .

Example enter image description here

PS: I am open to any type of solution using java, even the ones that use other libraries.

Using the following line works

g2D.setFont(new Font("Monospaced", Font.PLAIN, 12));

But there must be a more elegant solution that works for Any type of font .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:04:56+00:00Added an answer on May 26, 2026 at 9:04 pm

    The problem is that a space takes less horizontal space than a number in a proportional font. The easiest fix is to use a fixed-width font like this:

    g2D.setFont(new Font("Monospaced", Font.PLAIN, 12));
    

    before drawing the text.

    Making your own grid for when using a proportional font is also possible without using other libraries, but it is more work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to write a footer like this one Did i said that im
In trying to write more testable Java code, I have been using the Model-View-Presenter
Im trying to write a piece of code to set the image of the
I'm trying write a java program to send live microphone data over UDP, then
Trying to write a simple VCL program for educating purposes (dynamicly created forms, controls
Trying to write a GLOBAL CBT HOOK, this is My code, but my hooking
I'm trying to write a blog post which includes a code segment inside a
Trying to write a code that searches hash values for specific string's (input by
I trying to write a program that navigates the local file system using a
Been trying to write my own Prelude, and to write QuickCheck properties along with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.