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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:47:39+00:00 2026-05-31T12:47:39+00:00

I have a JPanel that has a null layout and I’m trying to add

  • 0

I have a JPanel that has a null layout and I’m trying to add a JSlider:

        slider = new JSlider();


        slider.setSize(300,30);
        slider.setPreferredSize(new Dimension(300,30));
        int x = (Constants.getScreenWidth()/2)-(slider.getWidth()/2);
        int y = (Constants.getScreenHeight()/2)-(slider.getHeight()/2);
        y = y - 100;
        slider.setLocation(x,y);
        slider.setBounds(x-(slider.getWidth()/2),y-(slider.getHeight()/2),300,30);


        add(slider);

however the slider is not showing up. I’ve printed the slider and it is:

javax.swing.JSlider[,420,320,300x30,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=288,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=300,height=30],isInverted=false,majorTickSpacing=0,minorTickSpacing=0,orientation=HORIZONTAL,paintLabels=false,paintTicks=false,paintTrack=true,snapToTicks=false,snapToValue=true]

why can’t I see the slider?

  • 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-31T12:47:41+00:00Added an answer on May 31, 2026 at 12:47 pm
    • remove slider.setLayout(null); you have set for setLayout(null); its parent in this case JPanel.setLayout(null);

    • disclaimer never use AbsoluteLayout for placing JComponent to the Container

    I’m able to display JSlider without code line

    int x = (Constants.getScreenWidth()/2)-(slider.getWidth()/2);
    int y = (Constants.getScreenHeight()/2)-(slider.getHeight()/2);
    y = y - 100;
    slider.setLocation(x,y);
    slider.setBounds(x-(slider.getWidth()/2),y-(slider.getHeight()/2),300,30);
    
    • place JComponent to the Container by using Insets

    this code showed JSlider on the screen

    import javax.swing.*;
    import java.awt.*;
    
    public class NullLayoutManagerWithJSlider extends JFrame {
    
        private JFrame frame = new JFrame();
        private static final long serialVersionUID = 1L;
    
        public NullLayoutManagerWithJSlider() {
            JSlider slider = new JSlider();
            slider.setPreferredSize(new Dimension(300, 30));        
            frame.setLayout(null);
            frame.add(slider);
    
            Insets mmInsets = frame.getInsets();
            Dimension sizeMmInn = null;
            slider.setPreferredSize(new Dimension(300, 30));
            sizeMmInn = slider.getPreferredSize();
            slider.setBounds(20 + mmInsets.left, 16 + mmInsets.top, sizeMmInn.width, sizeMmInn.height);
    
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocation(100, 100);
            frame.setSize(new Dimension(600, 400));
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    NullLayoutManagerWithJSlider cf = new NullLayoutManagerWithJSlider();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JPanel that has several (25) JLabel s on it, using a
I have a JScrollpane that has a JPanel on the inside (and the panel
I need to have a JToggleButton (that has custom background) that contains a JPanel
Right, I have a JTabbedPane that has a JPanel that contains a JLabel and
I have an existing interface that has a JPanel for displaying pdf files. It
I have a JPanel that encapsulates two JPanels, one on top of the other.
How can i draw 2d in a JPanel that i have on my GUI?
I have a Graphics object of JPanel and that is working fine: import java.awt.Color;
I have a JFrame that contains a display JPanel with JTextField and a control
I have a JPanel to which I'd like to add JPEG and PNG images

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.