Results 1 to 6 of 6
  1. #1
    sidharth is offline Member
    Join Date
    Nov 2009
    Posts
    8
    Rep Power
    0

    Default Problem with JEditor Pane while resizing the frame

    Hi , i am new to java GUI programming. i am adding a JEditor pane (with HTML text ) inside a JScrollPane and added the scroll pane to a JFrame.The problem is when i re size the frame the JEditor pane vanishes.

    Any one help me ?

    Following is the code :

    1. public class GridBagWithJEditorPane extends javax.swing.JFrame {
    2.
    3.
    4. public GridBagWithJEditorPane() {
    5. initComponents();
    6. }
    7.
    8. private void initComponents() {
    9. java.awt.GridBagConstraints gridBagConstraints;
    10.
    11. Panel1 = new javax.swing.JPanel();
    12. Button1 = new javax.swing.JButton();
    13. Label = new javax.swing.JLabel();
    14. Panel2 = new javax.swing.JPanel();
    15. ScrollPane = new javax.swing.JScrollPane();
    16. EditorPane1 = new javax.swing.JEditorPane();
    17.
    18. setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
    19. getContentPane().setLayout(new java.awt.GridBagLayout());
    20.
    21. Panel1.setLayout(new java.awt.GridBagLayout());
    22.
    23. Button1.setText("Button");
    24. Panel1.add(Button1, new java.awt.GridBagConstraints());
    25.
    26. Label.setText("Label");
    27. Panel1.add(Label, new java.awt.GridBagConstraints());
    28.
    29. gridBagConstraints = new java.awt.GridBagConstraints();
    30. gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    31. getContentPane().add(Panel1, gridBagConstraints);
    32.
    33. Panel2.setLayout(new java.awt.GridBagLayout());
    34.
    35. ScrollPane.setVerticalScrollBarPolicy(javax.swing. ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    36.
    37. EditorPane1.setContentType("text/html");
    38. EditorPane1.setText("<html>\r\n <head>\r\n\r\n </head>\r\n <body>\r\n <p style=\"margin-top: 0\">\r\n \rHere some html text sakdjslakdjsa dksa dsakjdklsajdklsad klsajd lksad<br>\n asdka;slkd;laskd;sa dlksa dksa dksald;lsakd;lsakd;l ska;dl sal;dk;salkd<br>\n asas;alks;laKSL;Kalk ALSKLAks;laSAsLAKS;Lk;slk<br>\t\n alsdasldk;alskd;laskd;l sadksa;dlksa;ldk;saldk;alsd<br>\n </p>\r\n </body>\r\n</html>\r\n");
    39. EditorPane1.setMinimumSize(new java.awt.Dimension(15, 15));
    40. EditorPane1.setPreferredSize(new java.awt.Dimension(340, 220));
    41. ScrollPane.setViewportView(EditorPane1);
    42.
    43. gridBagConstraints = new java.awt.GridBagConstraints();
    44. gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    45. gridBagConstraints.weightx = 1.0;
    46. gridBagConstraints.weighty = 1.0;
    47. Panel2.add(ScrollPane, gridBagConstraints);
    48.
    49. gridBagConstraints = new java.awt.GridBagConstraints();
    50. gridBagConstraints.gridx = 0;
    51. gridBagConstraints.gridy = 1;
    52. gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    53. getContentPane().add(Panel2, gridBagConstraints);
    54.
    55. pack();
    56. }
    57.
    58. public static void main(String args[]) {
    59. java.awt.EventQueue.invokeLater(new Runnable() {
    60. public void run() {
    61. new GridBagWithJEditorPane().setVisible(true);
    62. }
    63. });
    64. }
    65.
    66.
    67. private javax.swing.JButton Button1;
    68. private javax.swing.JEditorPane EditorPane1;
    69. private javax.swing.JLabel Label;
    70. private javax.swing.JPanel Panel1;
    71. private javax.swing.JPanel Panel2;
    72. private javax.swing.JScrollPane ScrollPane;
    73.
    74.
    75. }

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    1. I think the setMinimumSize()
    2. should be specified on the scrollpane
    3. and not on the EditorPane1.
    4. Also, please use code tags, it makes
    5. it a lot easier to read the code.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    Great this is a triple posting. Once here, once in at JavaRanch and once on StackOverflow. Since the OP is ignoring the advice given on the other forums you can guess my response here:

    ignoreList++

  4. #4
    sidharth is offline Member
    Join Date
    Nov 2009
    Posts
    8
    Rep Power
    0

    Default

    Hi Camickr ,, i will surely update in all the places whenever i got the answer ...now onwards i wont replicate the question ...thnks to remind me ,

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    Quote Originally Posted by sidharth View Post
    Hi Camickr ,, i will surely update in all the places whenever i got the answer ...now onwards i wont replicate the question ...thnks to remind me ,
    Famous last words, I provided an answer 9 hours ago. The OP has yet to respond to the 2 other sites where the question was cross posted.

  6. #6
    sidharth is offline Member
    Join Date
    Nov 2009
    Posts
    8
    Rep Power
    0

    Default

    Hi All,

    I got the answer ..please see :
    stackoverflow.com/questions/1714806/problem-with-jeditor-pane-while-resizing-the-frame

Similar Threads

  1. JFrame resizing problem
    By Bluefox815 in forum AWT / Swing
    Replies: 7
    Last Post: 02-24-2011, 07:56 PM
  2. Replies: 7
    Last Post: 11-02-2009, 06:31 PM
  3. Problem in resizing JTable in netbeans
    By shahid0627 in forum NetBeans
    Replies: 1
    Last Post: 09-07-2009, 06:33 PM
  4. panel resizing
    By kumar_gemi in forum New To Java
    Replies: 3
    Last Post: 03-13-2009, 02:51 AM
  5. Replies: 7
    Last Post: 07-09-2008, 12:06 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
  •