Results 1 to 6 of 6
- 11-11-2009, 05:38 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 8
- Rep Power
- 0
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. }
- 11-12-2009, 03:30 AM #2
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.
- 11-12-2009, 03:57 AM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
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++
- 11-12-2009, 06:05 AM #4
Member
- Join Date
- Nov 2009
- Posts
- 8
- Rep Power
- 0
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 ,
- 11-12-2009, 06:10 PM #5
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
- 11-13-2009, 05:43 AM #6
Member
- Join Date
- Nov 2009
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
JFrame resizing problem
By Bluefox815 in forum AWT / SwingReplies: 7Last Post: 02-24-2011, 07:56 PM -
Returning focus to a frame after hiding another frame
By fletcher in forum AWT / SwingReplies: 7Last Post: 11-02-2009, 06:31 PM -
Problem in resizing JTable in netbeans
By shahid0627 in forum NetBeansReplies: 1Last Post: 09-07-2009, 06:33 PM -
panel resizing
By kumar_gemi in forum New To JavaReplies: 3Last Post: 03-13-2009, 02:51 AM -
Problem in adding Multiple Panels at the Specific positon on frame
By SANDY_INDIA in forum AWT / SwingReplies: 7Last Post: 07-09-2008, 12:06 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks