CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
Wei Cui
Level 39
Newark
  • 08.04.2020
  • 611views
  • 1comment

need improve

Question about the task HTML Editor (part 6)
Java Multithreading,  Level 8,  Lesson 15
Resolved

Implement the initEditor() method, which initializes the editor panes. It must:
6.1. Set "text/html" as the content type for the htmlTextPane component.
Find and use the appropriate method.
6.2. Create a new local JScrollPane component based on htmlTextPane.
6.3. Add a tab named "HTML" and the component from the previous step to tabbedPane.
6.4. Create a new local JScrollPane component based on plainTextPane.
6.5. Add another tab named "Text" and the component from the previous step to tabbedPane.
6.6. Set the preferred pane size on tabbedPane.
6.7. Create a TabbedPaneChangeListener object and set it as a change listener on tabbedPane.
6.8. Add our tabbed pane to the center of the content pane of the current frame.
You can get the current frame's content pane using the getContentPane() method, which is inherited from JFrame.
Think about which method you need to call and with which arguments for the tabbed pane to be displayed in the center of the current frame's content pane.
After starting the application, you can see the latest results: two independent tabs (HTML and Text), and each of them lets you enter your own text.

Requirements:
  • 1. In the initEditor() method, the htmlTextPane component's content type must be set to "text/html" through the setContentType setter.
  • The initEditor() method should create a new local JScrollPane component using a constructor that takes htmlTextPane.
  • In the initEditor() method, a tab named "HTML" and a JScrollPane component created based on htmlTextPane must be added to the tabbedPane component.
  • The initEditor() method should create a new local JScrollPane component using a constructor that takes plainTextPane.
  • In the initEditor() method, a tab named "Text" and a JScrollPane component created based on plainTextPane must be added to the tabbedPane component.
  • In the initEditor() method, the preferred pane size must be set for the tabbedPane component using the setPreferredSize setter.
  • The initEditor() method must add a TabbedPaneChangeListener to the tabbedPane component using the addChangeListener method.
  • The initEditor() method must add the tabbed pane to the center of the current frame's content pane using the getContentPane().add() method.
package com.codegym.task.task32.task3209; import javax.swing.text.html.HTMLDocument; import java.io.File; public class Controller { private View view; private HTMLDocument document; private File currentFile; public Controller(View view) { this.view = view; } public void init() {} public void exit() { System.exit(0); } public static void main(String[] args) { View view = new View(); Controller controller = new Controller(view); view.setController(controller); view.init(); controller.init(); } public static class ExceptionHandler { public static void log(Exception e) { } } }
+2
Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Wei Cui
Level 39 , Newark, United States
8 April 2020, 19:54solution
public void initEditor() {
    htmlTextPane.setContentType("text/html");

    JScrollPane htmlScorllPane = new JScrollPane(htmlTextPane);
    tabbedPane.addTab("HTML", htmlScorllPane);

    JScrollPane plainTextScrollPane1 = new JScrollPane(plainTextPane);
    tabbedPane.addTab("Text", plainTextScrollPane1);

    tabbedPane.setPreferredSize(new Dimension(700, 500));

    tabbedPane.addChangeListener(new TabbedPaneChangeListener(this));

    this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
}
+8
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.