Results 1 to 2 of 2
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Rep Power

    Default page view prelude

    About one week ago I had never heard of a SSCCE (I had to look it up).
    Now I know what is a SSCCE and I want you please to comment on one.
    I would like to use this model as a page-view presentation of a JTextPane.
    But before to get into that I would like you to comment first one some "domestic"
    this like:
    1) what goes in the main/ constructor/ and GUI method: I'd very much like to get things right now!
    (I know that it is preferable that all the GUI gets initiated through the EventQueue.invokeLater thread
    that I still might have to add, right?);

    2) The combo stretches out -- because of the flow layout of the border north?-- in an ugly manner!
    How to make it neat and small (tried several thinks like box and grid layout and setSize);

    3) At the PagePane class I will "paint" the text in a page viewed rectangled presentation using FontMetrics
    I will do the line break and page break by using the width and hight methods (I know that this is
    probably not the way to go but I looked in other strategies and did not understand them).

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import javax.swing.text.*;
    public class ModelPageView {
        private JTextPane textpane;
        public ModelPageView() {
            StyledDocument doc = new DefaultStyledDocument();
            StyledEditorKit styleEditKit = new StyledEditorKit();
            textpane = new JTextPane();
            PagePane pp = new PagePane(textpane);
        public JPanel doGUI() {
            JPanel jp = new JPanel(new BorderLayout());
            JScrollPane spane = new JScrollPane(textpane);
            spane.setPreferredSize(new Dimension(780, 830));
            jp.add(spane, BorderLayout.CENTER);
            jp.add(doSizeCombo(), BorderLayout.NORTH);
            return jp;
        public JComboBox doSizeCombo() {
            String[] size = {"font-size-12", "font-size-14", "font-size-16",
            "font-size-18", "font-size-24", "font-size-36", "font-size-48"};
            final JComboBox combo = new JComboBox(size); //combo.setName("fontsize");
            combo.setSize(200, combo.getPreferredSize().height);
            combo.addActionListener(new ActionListener()  {
                public void actionPerformed(ActionEvent event) {            
                    Action action = textpane.getActionMap().get(combo.getSelectedItem());
            return combo;
        public static void main(String[] arg) {
            JFrame frame = new JFrame();
            frame.setTitle("Willem Writer");
            frame.setBounds(100, 30, 600, 400);
            ModelPageView  mpv = new ModelPageView();
            Container c = frame.getContentPane();
        public class PagePane extends JPanel{
             JTextPane textpane;
             public PagePane(JTextPane textpane) {
                this.textpane = textpane;
                JScrollPane sPane = new JScrollPane(this);
                this.setPreferredSize(new Dimension(500, 2000));
                JFrame frame = new JFrame("The Pageview Screen" );
                frame.setBounds(750, 30, 800, 1000);
            public void paintComponent(Graphics g) {
                g.drawRect(50, 50,700, 850);
                g.drawRect(50, 950,700, 850);
    Last edited by willemjav; 03-06-2014 at 12:29 PM.

  2. #2
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Rep Power

    Default Re: page view prelude

    For not creating with each size change an action object I could say this instead (47/48):
    textpane.getActionMap().get(combo.getSelectedItem( )).actionPerformed(null);

Similar Threads

  1. Replies: 0
    Last Post: 04-24-2013, 12:07 AM
  2. unnable to view the default home page though j2ee server starting properly
    By shallz in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 03-21-2009, 09:37 AM
  3. setting the view to a jsp page from a self refeshing page
    By deepal_205 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 08-15-2008, 04:41 PM
  4. Applet - enter URL and view the page
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-10-2008, 02:38 PM
  5. How to view applet from html page.
    By jwzumwalt in forum Java Applets
    Replies: 2
    Last Post: 11-24-2007, 04:21 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