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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:54:53+00:00 2026-06-09T22:54:53+00:00

So, I’m making a kind of text editor, and I need a JScrollPane for

  • 0

So, I’m making a kind of text editor, and I need a JScrollPane for vertical navigation.
But I can’t get it to work.

I have read every freaking tutorial on first ten pages of google results, and I can’t get it to work.

Lets say I have JFrame (size 1000×800). I want to put a JPanel (1000×2000) in it so that it horizontally alignes with the JFrame. I want to stick a simple scroll bar to the right side of the JPanel so I can get to the rest of it.

I have reduced sizes, I have added JPanel to JScrollBar and vice versa, added one of them to JFrame, both, none, but nothing.

So, at this point, I wouldn’t mind a couple of lines of finished code…

EDIT: Fine, here’s the code…

mWindow = new JFrame(lang.getString("title"));
mWindow.setSize(1000, 800);
mWindow.setLocationRelativeTo(null);
mWindow.setResizable(false);
mWindow.setLayout(null);
mWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mWindow.setVisible(true);

workspace = new JPanel();
workspace.setBounds(0,0, 1000, 1203);
workspace.setBackground(Color.RED);

scroll = new JScrollPane(workspace, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.setBounds(0, 20, 600, 600);
//scroll.setLayout(null);
mWindow.getContentPane().add(scroll);
mWindow.repaint();
mWindow.validate();

That shows a part of JPanel (600X600, (JScrollPane size)), and shows scrollbars, but isn’t scrollable

  • 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-09T22:54:53+00:00Added an answer on June 9, 2026 at 10:54 pm

    So, I did this really quick test and it works fine for me…

    public class TestPane extends JPanel {
    
        public TestPane() {
    
            setBorder(new LineBorder(Color.RED));
            // This is for demonstration purposes only
            // One should always rely on the layout manager
            // to define this value
            // Thank kleopatra 
            setPreferredSize(new Dimension(1000, 1000));
    
        }
    
        @Override
        protected void paintComponent(Graphics g) {
    
            super.paintComponent(g);
    
            FontMetrics fm = g.getFontMetrics();
    
            Dimension size = getPreferredSize();
            String text = "Pref: " + size.width + "x" + size.height;
            g.drawString(text, 0, fm.getAscent());
    
            size = getSize();
            text = "Size: " + size.width + "x" + size.height;
            g.drawString(text, 0, fm.getHeight() + fm.getAscent());
    
        }
    
    }
    

    And the test frame

    public class TestFrame {
    
        public static void main(String args[]) {
    
            JFrame frame = new JFrame();
            frame.setLayout(new BorderLayout());
    
            JScrollPane scroll = new JScrollPane(new TestPane());
    
            frame.add(scroll);
    
            frame.setSize(500, 500);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    
        }
    
    }
    

    Which produces this:

    Scroll away

    On a side note, I don’t know why people insist on using null layouts, they just cause more trouble and heart ache then they’re worth. Take the time to find some simple layout managers. I hate VB for a lot of reasons, but layout management is at the top of my list, IMHO

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.