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

  • Home
  • SEARCH
  • 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 6629449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:15:44+00:00 2026-05-25T22:15:44+00:00

I have a Java Swing application that i want to create a nice component

  • 0

I have a Java Swing application that i want to create a nice component in it like a component in Microsoft word. In Microsoft word you can change the margins of your document like in here :
enter image description here

The trick here is that if you change the Top margins to (Let’s say) 1.5″ then the Preview image will change to show this, so the lines will move down a bit in the image to show that change in the margins so the user can feel how much his document will be affected by this change. So for example if i change the left margin to (4.0″) the image will look like this :

enter image description here

What i did is create 2 images a blank page image + another image that contains lines only(Lines image), like these 2 images :

enter image description here
enter image description here

I inserted each image in a JLabel above each other, and now when i change the JSpinner top margin value, i keep the “blank page” image fixed, but i change the border of the “lines image” to move it down a bit. The trick worked fine for the top margin, but the behavior goes totally wrong if i change the bottom/right/left margins.

Here is my code that i apply when changing any JSpinner value :

private void marginSpinnerStateChanged() {
    //1. Get the approximate values of all margins :
        int topMargin = (int)( Float.valueOf( topSpinner.getValue().toString() ) * 8 );
        int bottomMargin = (int)( Float.valueOf( bottomSpinner.getValue().toString() ) * 8 );
        int leftMargin = (int)( Float.valueOf( leftSpinner.getValue().toString() ) * 8 );
        int rightMargin = (int)( Float.valueOf( rightSpinner.getValue().toString() ) * 8 );

    //2. Apply all specified margins to the lines label : 
        linesLabel.setBorder( new EmptyBorder( topMargin, leftMargin, bottomMargin, rightMargin ) );
}

Can you help me continue this to work right ?

  • 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-25T22:15:45+00:00Added an answer on May 25, 2026 at 10:15 pm

    You could just draw the image on top of the paper and scale the image as you go. So you would override the paintComponent() method of a JComponent to do something like:

    g.drawImage(image, x, y, width, height, null);
    

    x – would be the left margin
    y – would be the top margin
    width – would be (maxWidth – leftMargin – rightMargin)
    height – would be (maxHeight – topMargin – bottomMargin)

    If you don’t like scaling the image you can always use a BufferedImage and then use the getSubImage(…) method to get an image the desired size to be painted.

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

Sidebar

Related Questions

I would like to create extend a Java Swing application to have a look
I have a swing Java application that preserves a lot of data (you can
I have a Java Swing application client that I want to use to consume
I have a small Java Swing application that I want to rewrite in WPF
I have a Java Swing application that i want to run on Mac OS
I have made a small java swing application that I want to share with
I have a Java Swing application that is being used as a cluster application.
I have a Java swing application with a panel that contains three JComboBoxe s
I've creating a Java Swing application and I realized that I have many many
We have a client side application (Java/Swing) that we need an HTML rendering control

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.