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 7041577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:03:46+00:00 2026-05-28T02:03:46+00:00

I’m making a simple Kakuro application in Java Swing and I have used JButton

  • 0

I’m making a simple Kakuro application in Java Swing and I have used JButtons as cells. I’ve done everything from generating the grid (setBackground(Color.BLACK) and setBackground(Color.WHITE)) to filling with unique numbers.

But the problem is, I don’t know how to paint the “clues” at the ends of JButtons. What I want is similar to:

enter image description here

Sometimes the numbers may appear on only 3 sides, 2 sides or even 1 side.

I thought of setting background images, but its not possible as the numbers are sums of dynamically generated numbers (the grid is dynamic).

So any idea how to get this kind of JButton? Or if its not possible, what other options do I have?

Thanks a lot in advance (I’m really stuck).

  • 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-28T02:03:46+00:00Added an answer on May 28, 2026 at 2:03 am

    very simple and confortable way is add JLabels to the JButton by using BorderLayout,

    import java.awt.BorderLayout;
    import java.awt.Color;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.SwingUtilities;
    
    public class FourLabelsInButton {
    
        private JFrame frame;
        private JButton myButton1;
        private JLabel myButton1_Label_N;
        private JLabel myButton1_Label_E;
        private JLabel myButton1_Label_W;
        private JLabel myButton1_Label_S = new JLabel();
    
        public FourLabelsInButton() {
            myButton1_Label_N = new JLabel("45");
            myButton1_Label_N.setHorizontalAlignment(JLabel.CENTER);
            myButton1_Label_N.setForeground(Color.red);
    
            myButton1_Label_E = new JLabel("1");
            myButton1_Label_E.setHorizontalAlignment(JLabel.CENTER);
            myButton1_Label_E.setForeground(Color.red);
    
            myButton1_Label_W = new JLabel("9");
            myButton1_Label_W.setHorizontalAlignment(JLabel.CENTER);
            myButton1_Label_W.setForeground(Color.red);
    
            myButton1_Label_S = new JLabel("21");
            myButton1_Label_S.setHorizontalAlignment(JLabel.CENTER);
            myButton1_Label_S.setForeground(Color.red);
    
            myButton1 = new JButton();
            myButton1.setBackground(Color.black);
            myButton1.setLayout(new BorderLayout());
            myButton1.add(myButton1_Label_N, BorderLayout.NORTH);
            myButton1.add(myButton1_Label_E, BorderLayout.EAST);
            myButton1.add(myButton1_Label_W, BorderLayout.WEST);
            myButton1.add(myButton1_Label_S, BorderLayout.SOUTH);
    
            frame = new JFrame();
            frame.add(myButton1);
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    FourLabelsInButton ggg = new FourLabelsInButton();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.