Results 1 to 8 of 8
  1. #1
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default Help adding JScrollBar/JScrollPane to JTextPane

    Java Code:
        protected class AgreementUI extends JFrame implements ActionListener{
        	
            private JTextPane pane = new JTextPane();
            private JPanel panel = new JPanel();
            private JButton agree = new JButton();
            private JScrollPane bar = new JScrollPane();
            protected AgreementUI(){
                start();
            }
    
            private void start(){
    
                setTitle("RS2Bot| License agreement (" + accName + ")");
                setIconImage(new ImageIcon("./images/logo.png").getImage());
                setSize(410,380);
                setLocationRelativeTo(getOwner());
                setLayout(null);
                setResizable(false);
    
                panel.setBounds(5,5,390,290);
                panel.setBorder(BorderFactory.createTitledBorder("RS2Bot License agreement"));
    
                pane.setEditable(false);
                pane.setBounds(35,39,330,240);
                pane.setContentType("text/plain");
                pane.setContentType("text/html");
                pane.setText(getAgreementText());
    
                agree.setBounds(130,300,150,30);
                agree.setIcon(new ImageIcon("./images/accept.gif"));
                agree.setText("Accept");
                agree.addActionListener(this);
                agree.setActionCommand("agree");
                
                JScrollPane scroller = new JScrollPane(pane);
               
                
                
                
                
                add(scroller);
                add(agree);
                add(pane);
                add(panel);
                
                
              
    
            }
    
            private String getAgreementText(){
                String text = "";
                try{
    
                    FileInputStream fstream = new FileInputStream("./AGREEMENT");
    
                    DataInputStream in = new DataInputStream(fstream);
                    BufferedReader br = new BufferedReader(new InputStreamReader(in));
                    String strLine;
    
                    while ((strLine = br.readLine()) != null)   {
                      text = "\n" + text + "\n"+ strLine;
                    }
    
                    in.close();
                    } catch (Exception e){
                    e.printStackTrace();
                      JOptionPane.showMessageDialog(null,"Unable to get agreement/license file. Make sure to download a licensed copy from our site. Now aborting");
                      System.exit(0);
                    }
                return text;
            }
    
            public void actionPerformed(ActionEvent e) {
                String cmd = e.getActionCommand();
    
                if(cmd.contains("agree")){
                    setVisible(false);
                    dispose();
                    JOptionPane.showMessageDialog(null,"We are now ready to start the bot. Press okay to continue");
                    new AppletUI().setVisible(true);
                  new RunScript().run(scriptName);
                }
    
            }
        }
    Why does the JScrollPane not work? It does not even show. What am I doing wrong? Thanks! =D

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You appear to be adding your JTextPane, pane, to more than one container including the JScrollPane (actually it's JViewport) and the JFrame. It makes sense that this will cause problems.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Also:
    1) You have set the bounds for all but the most important item, the JScrollPane.
    2) Regardless, you should avoid null layout and setBounds but instead use the layout managers.
    3) This window appears to want to behave more like a JDialog than a JFrame. Perhaps you wish to change this?
    4) When asking about GUI issues, please post a small compilable program that we can run and test it.

    For example
    Java Code:
    import java.awt.event.*;
    import javax.swing.*;
    
    public class FuSwing1 extends JDialog {
    
       private JTextPane pane = new JTextPane();
       private JPanel panel = new JPanel();
       private JButton agree = new JButton();
    
       public FuSwing1(JFrame frame) {
          super(frame, true);
          start();
       }
    
       private void start() {
          setTitle("RS2Bot| License agreement (Agreement)");
          setSize(410, 380);
          setLocationRelativeTo(null);
          setLayout(null);
          setResizable(false);
    
          panel.setBounds(5, 5, 390, 290);
          panel.setBorder(BorderFactory.createTitledBorder("RS2Bot License agreement"));
    
          pane.setEditable(false);
          //pane.setBounds(35, 39, 330, 240);
          pane.setContentType("text/plain");
          pane.setContentType("text/html");
          pane.setText(getAgreementText());
    
          agree.setBounds(130, 300, 150, 30);
          agree.setText("Accept");
          agree.setActionCommand("agree");
    
          JScrollPane scroller = new JScrollPane(pane);
          scroller.setBounds(35, 39, 330, 240);
    
          add(scroller);
          add(agree);
          //add(pane);
          add(panel);
    
       }
    
       private String getAgreementText() {
          StringBuilder sBuilder = new StringBuilder();
          for (int i = 0; i < 200; i++) {
             sBuilder.append("Agreement Text,  ");
          }
          
          return sBuilder.toString();
       }
    
       private static void createAndShowUI() {
          JFrame frame = new JFrame("original");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          
          FuSwing1 fs1 = new FuSwing1(frame);
          fs1.setVisible(true);
          
          frame.dispose();
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    
    }

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Also, I believe that the second line here nullifies the first:
    Java Code:
                pane.setContentType("text/plain");
                pane.setContentType("text/html");
    Which contentType do you really want to have?

  5. #5
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    Thanks fubarable for your reply,
    Yeah, I made a few mistakes (I meant the text/html). But why isn't the scrollpane attached to the Jtextpane?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by crikey View Post
    Thanks fubarable for your reply,
    Yeah, I made a few mistakes (I meant the text/html). But why isn't the scrollpane attached to the Jtextpane?
    I gave you the reasons in my posts above.

    It is when I tried as in my example above. If you're still having problems, let's see your latest code attempt, but please make it a small wholly contained program, an SSCCE, like my example above.
    Last edited by Fubarable; 08-29-2010 at 11:10 PM.

  7. #7
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    Java Code:
    setTitle("RS2Bot| License agreement (Agreement)");
                setSize(410, 380);
                setLocationRelativeTo(null);
                setLayout(null);
                setResizable(false);
    
                panel.setBounds(5, 5, 390, 290);
                panel.setBorder(BorderFactory.createTitledBorder("RS2Bot License agreement"));
    
                pane.setEditable(false);
                pane.setBounds(35, 39, 330, 240);
                pane.setContentType("text/plain");
                pane.setContentType("text/html");
                pane.setText(getAgreementText());
    
                agree.setBounds(130, 300, 150, 30);
                agree.setText("Accept");
                agree.addActionListener(this);
                agree.setActionCommand("agree");
    
                JScrollPane scroller = new JScrollPane(pane);
                scroller.setBounds(35, 39, 330, 240);
    
                add(scroller);
                add(agree);
                //add(pane);
                add(panel);
    still does not work. I hear a 'beep' noise (getAgreementText has roughly 25,000 characters) and it displays no text.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by crikey View Post
    still does not work. I hear a 'beep' noise (getAgreementText has roughly 25,000 characters) and it displays no text.
    Your code does not compile nor run for me, so I'm at a loss to help you. If you desire our help, you may have to have to put in more effort. Please re-read my previous post and its link which I'll repost here:

    Quote Originally Posted by Fubarable View Post
    If you're still having problems, let's see your latest code attempt, but please make it a small wholly contained program, an SSCCE, like my example above.

Similar Threads

  1. Replies: 1
    Last Post: 06-07-2010, 07:10 AM
  2. problem in adding jscrollbar to panel
    By Mani_4 in forum AWT / Swing
    Replies: 6
    Last Post: 06-06-2010, 11:46 AM
  3. Problem with JScrollBar
    By Arthur in forum AWT / Swing
    Replies: 3
    Last Post: 02-19-2010, 02:59 AM
  4. Problem in adding new JTextPane at Runtime
    By png in forum AWT / Swing
    Replies: 12
    Last Post: 12-14-2009, 12:14 PM
  5. JScrollBar
    By solomon_13000 in forum AWT / Swing
    Replies: 1
    Last Post: 07-01-2009, 07:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •