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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:37:45+00:00 2026-06-04T22:37:45+00:00

How can i have this image like below into the slavePanel and on top

  • 0

How can i have this image like below into the slavePanel and on top of that JPanel adjust the JButtons which looks like the image but having buttons correctly wrapped around? (Right now they are shaped in 1 row, 4 column)

enter image description here

  //
  // Shot Gun mover up/down/left/right, middle on is for zoom
  //
  public void GunMover(JPanel configPanel) throws IOException {

    // Master Panel - holds everything
    JPanel masterPanel = new Panel();
    masterPanel.setLayout(new SpringLayout());

    // Slave Panel - with image background 
    JPanel slavePanel = new Panel();
    slavePanel.setLayout(new SpringLayout());

    // Row 1
    final JButton ptzLeft = new JButton("<");       
    masterPanel.add(ptzLeft, BorderLayout.WEST);

    // Row 2
    final JButton ptzRight = new JButton(">");   
    masterPanel.add(ptzRight, BorderLayout.CENTER);    

    // Row 3
    final JButton ptzUp = new JButton("^");   
    masterPanel.add(ptzUp, BorderLayout.WEST);    

    // Row 4
    final JButton ptzDown = new JButton("down");   
    masterPanel.add(ptzDown, BorderLayout.CENTER);    

    // How do i add slavePanel this background and add all the JButtons 
    // According to that image shape?

    // Layout the panel.
    SpringUtilities.makeCompactGrid(masterPanel,
                                1, 4, //rows, cols
                                6, 6, //initX, initY
                                6, 6);        

    configPanel.setLayout(new GridLayout(0,1));
    configPanel.add(masterPanel);   
  }

Follow up: Excellent one from Andrew Thompson + at-least my broken method

enter image description here

package test;

import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import javax.swing.*;

public class New extends JFrame {

  private static final long serialVersionUID = 1L;
  private ImageIcon errorIcon =
          (ImageIcon) UIManager.getIcon("OptionPane.errorIcon");
  private Icon infoIcon =
          UIManager.getIcon("OptionPane.informationIcon");
  private Icon warnIcon =
          UIManager.getIcon("OptionPane.warningIcon");

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        New t = new New();
      }
    });
  }

  public New() {
    setLayout(new BorderLayout());

    JPanel slavePanel = new NewPanel();
    slavePanel.setLayout(new GridLayout(0, 2, 4, 4));
    add(slavePanel);    

    JButton button = new JButton();
    button.setBorderPainted(false);
    button.setBorder(null);
    button.setFocusable(false);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setContentAreaFilled(false);
    button.setIcon((errorIcon));
    button.setRolloverIcon((infoIcon));
    button.setPressedIcon(warnIcon);
    button.setDisabledIcon(warnIcon);
    slavePanel.add(button);    

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
  }
}


package test;

import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.Border;

public class NewPanel extends JPanel {

  private Image imageGui;
  private static Dimension screen;

  public NewPanel() {
    try {
      imageGui =
              ImageIO.read(
              (InputStream) NewPanel.class.getResourceAsStream(
              "/image/ptz.png"));
    } catch (IOException e) {
      e.printStackTrace(System.err);
    }

    Border border = BorderFactory.createEmptyBorder(11, 11, 11, 11);
    setOpaque(true);
    setBorder(border);
    setFocusable(true);
    setSize(getPreferredSize());
    revalidate();
    repaint();
    setVisible(true);
  }

  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawImage(imageGui, 0, 0,
            imageGui.getWidth(null), imageGui.getHeight(null), null);
    revalidate();
    repaint();
  }

  @Override
  public Dimension getPreferredSize() {
    return new Dimension(imageGui.getWidth(null), imageGui.getHeight(null));
  }
}
  • 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-06-04T22:37:47+00:00Added an answer on June 4, 2026 at 10:37 pm
    1. Use a 3×3 GridLayout
    2. For each of the 9 cells get a subimage:
    • For every second component, add a label with the subimage.
    • For every other component, add a JButton from which the space is removed. Use the subimage as icon, but you’ll need alternate icons to indicate focus, activation etc. This example puts a red border around the ‘pressed’ icon.

    Compass Buttons

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    import java.net.URL;
    import javax.imageio.ImageIO;
    
    public class CompassButtons {
    
        public CompassButtons(BufferedImage bi) {
            int w = bi.getWidth();
            int h = bi.getHeight();
            int step = w / 3;
            JPanel p = new JPanel(new GridLayout(3, 3));
            p.setBackground(Color.BLACK);
            int count = 0;
            for (int ii = 0; ii < w; ii += step) {
                for (int jj = 0; jj < h; jj += step) {
                    // This is it - GET THE SUB IMAGE
                    Image icon = bi.getSubimage(jj, ii, step, step);
                    if (count % 2 == 1) {
                        JButton button = new JButton(new ImageIcon(icon));
    
                        // make it transparent
                        button.setContentAreaFilled(false);
    
                        // remove border, indicate press using different icon
                        button.setBorder(null);
    
                        // make a 'pressed' icon..
                        BufferedImage iconPressed = new BufferedImage(
                                step, step, BufferedImage.TYPE_INT_ARGB);
                        Graphics g = iconPressed.getGraphics();
                        g.drawImage(icon, 0, 0, p);
                        g.setColor(Color.RED);
                        g.drawRoundRect(
                                0, 0,
                                iconPressed.getWidth(p) - 1, 
                                iconPressed.getHeight(p) - 1,
                                12, 12);
                        g.dispose();
                        button.setPressedIcon(new ImageIcon(iconPressed));
    
                        button.setActionCommand("" + count);
                        button.addActionListener((ActionEvent ae) -> {
                            System.out.println(ae.getActionCommand());
                        });
    
                        p.add(button);
                    } else {
                        JLabel label = new JLabel(new ImageIcon(icon));
                        p.add(label);
                    }
                    count++;
                }
            }
            JPanel center = new JPanel(new GridBagLayout());
            center.setBackground(Color.BLACK);
            center.add(p);
            JOptionPane.showMessageDialog(null, center);
        }
    
        public static void main(String[] args) throws Exception {
            URL url = new URL("https://i.stack.imgur.com/SNN04.png");
            final BufferedImage bi = ImageIO.read(url);
            SwingUtilities.invokeLater(() -> {
                new CompassButtons(bi);
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can I do this? I have an image 50x50 and I would like
Hi I have a form class which looks like below:- class UserCreateForm(wtf.Form): name=wtf.TextField('Name',validators=[validators.Required(),username_check]) email=wtf.TextField('Email')
I have a Dell Inspiron E1505 and as you can see in this image
I have line: imagejpeg($this->image, $file, $quality); How can add on this image watermark.png?
I have an image $(#main) how can I use jquery to dosomething(this) when the
I have an app that can make modify images. In some cases, this makes
I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
I have a code setup something like below, the image is part of a
I have this code which gives me the below output in firebug, so according
I have a UIView that I would like to animate into the screen in

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.