JTextPane Visualization Problem!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JTextPane Visualization Problem!

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Posts
    1

    JTextPane Visualization Problem!

    I am trying to display a JtextPane embedded into a JScrollPane in a JFrame. But I can only see the JScrollPane (not the JTextPane) in the JFrame. Here is my code:


    public class JTextPaneTest extends JFrame {

    public static void main(String args[]) {
    try {
    JTextPaneTest frame = new JTextPaneTest();
    frame.setVisible(true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    public JTextPaneTest() {
    super();
    getContentPane().setBackground(new Color(241, 243, 248));
    //setBounds(100, 100, 500, 375);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().setLayout(null);
    //this.setPreferredSize(new Dimension(1020,730));
    this.setSize(536, 300);
    this.setLocationRelativeTo(null);

    final JTextPane textPane_1 = new JTextPane();
    textPane_1.setText("New JTextPane");

    final JScrollPane statisticsScrollPane = new JScrollPane(textPane_1);
    statisticsScrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Statistics", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, new Color(0, 128, 255)));
    statisticsScrollPane.setLayout(null);
    statisticsScrollPane.setBounds(6, 14, 486, 140);
    getContentPane().add(statisticsScrollPane);

    }
    }



    Just wondering, what am I doing wrong? Please help.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You must add the component to the scrollpane's viewport. I have
    removed some unnecessary final declarations also, and used a GridLayout
    for the frame's contentpane.

    Code:
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    
    public class JTextPaneTest extends JFrame {
    
      JTextPane textPane_1 = new JTextPane();
      JScrollPane statisticsScrollPane = new JScrollPane();
    
      public static void main(String args[]) {
        try {
          JTextPaneTest frame = new JTextPaneTest();
          frame.setVisible(true);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    
      public JTextPaneTest() {
        getContentPane().setLayout(new GridLayout());
        getContentPane().setBackground(new Color(241, 243, 248));
        setBounds(100, 100, 500, 375);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        textPane_1.setText("New JTextPane");
    
        statisticsScrollPane.getViewport().add(textPane_1,null);
    
        statisticsScrollPane.setBorder(new TitledBorder(new EtchedBorder(),
            "Statistics", TitledBorder.DEFAULT_JUSTIFICATION,
            TitledBorder.DEFAULT_POSITION, null, new Color(0, 128, 255)));
    
        statisticsScrollPane.setBounds(6, 14, 486, 140);
        getContentPane().add(statisticsScrollPane);
    
      }
    }
    eschew obfuscation

Similar Threads

  1. Problem with Search
    By Irina in forum ASP.NET
    Replies: 0
    Last Post: 11-29-2002, 10:47 PM
  2. Replies: 0
    Last Post: 12-13-2001, 12:06 PM
  3. a problem with font and language
    By Roseta in forum VB Classic
    Replies: 0
    Last Post: 11-14-2001, 03:24 AM
  4. Arabic problem view
    By Ayman in forum VB Classic
    Replies: 0
    Last Post: 04-03-2000, 01:08 AM
  5. Problem with CryptoAPI and JCE
    By Jason Bock in forum VB Classic
    Replies: 0
    Last Post: 03-21-2000, 06:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center