JInternalFrame vs JFrame behaviour

I have a tested JFrame with a set of swing components. This frame works fine, but when
I used the code of the frame to create a JInternalFrame with the same components the
lower part of the frame is not shown. The frame is cutted in the lower border.
Thanks in advance.

Did you use:
internalFrame.pack();
This makes sure the size of the frame is large
enought to show all the components at their preferred
sizes.In addition to that, verify that the JInternalFrame is not simply bigger than its JDesktopPane.

Similar Messages

  • Strange JFRAME behaviour under Jdk 1.5

    I have the following extracted code :
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.geom.*;
    public class DrawPie extends JFrame{
         private HashMap ColourMap=new HashMap();;
         private HashMap DataMap=new HashMap();
         private double Total_Val=0;
         private int startAngle=0;
         private int arcAngle=0;
         public DrawPie(HashMap DataMap){
         super ("Pie Chart Analysis");
              this.DataMap=DataMap;
         //     System.out.println("DATAMap-->"+DataMap);
         // getContentPane().setBackground(Color.white);
              setSize(500,500);
              setVisible(true);
         public void paint(Graphics g){
              super.paint (g);
              Graphics2D g2 = (Graphics2D) g;
              DrawPieChart(g);
    This programme work fine under jdk1.4.2 or below at the time when the Jframe or windows is resized or icon minimised or maximised.
    But when it was compiled using latest jdk1.5 , unexpected strange result happen , the pie chart draw using java 2d
    g2.fill(new Arc2D.Double(30, 30, 200,200,startAngle,arcAngle
    , Arc2D.PIE));
    wil behaved strangely, the moment the JFrame or windows is resize or dragged.
    The pie chart will disappear if the windows is resized , However if the window is minimised and restore back to normal size , pie chart will reappear and subsequently lost completely if the windows is dragged resulted in the size changes.
    I was puzzled by this strange swing behaviour , any resized or windows minimise or maximise would not result in the lost of pie chart as long as the jdk is not 1.5 ! Was it due to swing fundamental changes incorporated in the latest release?
    Any suggestion?
    Thank

    ok I see what you have done,
    now a few tips in drawing something on your frame:
    never override the paint method of your main Frame (like you did)
    to draw something on it you simply override the contentPane's paint method
    and to make your own contentPane you simply make one by making a new Class
    that extends say JPanel and assign it as a contentPane of your Frame(like I did)
    And in this Paint method you can draw whatever you like it will be properly uptated!!!
    All the best keep up the good work!
    ps. try the code bellow.
    import javax.swing.*;
    public class DrawPie1 extends JFrame {
    private double Total_Val=0;
    private int startAngle=0;
    private int arcAngle=0;
    private MyMainPanel mainPan;
    public DrawPie1()
    super ("Pie Chart Analysis");
    mainPan = new MyMainPanel();
    setContentPane(mainPan);
    //public void paint(Graphics g) //Do not override the paint method of your main frame!!
    // super.paint (g);
    // Graphics2D g2 = (Graphics2D) g;
    // g2.setPaint(Color.red);
    // g2.fill(new Arc2D.Double(30, 30, 200,200,0,78
    // , Arc2D.PIE));
    public static void main(String args[])
    DrawPie1 pie=new DrawPie1();
    pie.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pie.setSize(400,300);
    pie.setVisible(true);
    //**** Second Class
    import javax.swing.*;
    import java.awt.*;
    import java.awt.geom.Arc2D;
    public class MyMainPanel extends JPanel
    public MyMainPanel()
    public void paint(Graphics g)
    super.paint (g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setPaint(Color.red);
    g2.fill(new Arc2D.Double(30, 30, 200,200,0,78
    , Arc2D.PIE));
    }

  • Weird JFrame behaviour in 1.4.1

    I have an application that runs fine under 1.4.0. It has a main JFrame where most of the action happens, but from time to time, it wants to display another JFrame, which is hassle-free under 1.4.0.
    Under 1.4.1, the main JFrame is fine, but the second JFrame only semi-displays, and I've tried to figure it out, but nothing I'm trying is helping. You can see a small part of the top left-hand corner of the frame, and you can see its edges, and you can click on the menu bar, which will popup the menu items, which are functional. The rest of the frame looks like whatever is behind it: if you drag it around, the copied background moves around too, but if you drag it partially offscreen, then when you drag it back, it contains sort of skidmarks or smears (stuff that was at the visible edge, smears).
    I'm at a loss as to what could be causing this weird behaviour, and would appreciate any insights or clues as to how to (continue to) go about fixing it.
    Thanks
    Charlene Abrams
    Tripos, Inc
    St Louis, MO

    Then maybe you have some code that is catching an exception and ignoring it.
    Do you have any empty catch clauses?
    catch (SomeEvent e) { }

  • Enable/Disable JMenu in JFrame on click of button in JInternalFrame

    Hello there. Could anybody help me out of the situation?
    I am trying to enable/disable JMenu of JFrame on click of a button which is in JInternalFrame.
    I want to set JMenu(this is in JFrame).setEnable(true) in ActionPerformed() of JInternalFrame, but JFrame and JInternalFrame are the different classes and I do not know how I can access JMenu in main frame.
    How should I write something like mainframe.menu.setEnabled(true) from internal frame?
    For JInternalFrame window action, there is JInternalFrameListener, but this is not relevant for my situation because I am trying to control on click of a button.
    Can anybody suggest a solution?

    // Main Frame
    public class MainFrame extends JFrame
         public MainFrame()
              InternalFrame l_int = new InternalFrame(this);
                    //try to initiate internal frame like this
         public void activateMenu()
              menuBar.setEnabled(true);
         public static void main(String args[])
              MainFrame mainframe = new MainFrame();
    // Internal Frame
    public class InternalFrame extends JInternalFrame
         private MainFrame m_mainFrm = null;
         public InternalFrame(MainFrame a_objMainFrame)
              //your own code
              m_mainFrm = a_objMainFrame;
         public void actionPerformed(ActionEvent a_objevent)
    if(m_mainFrm != null)
              m_mainFrm.activateMenu();
    }try this.. hope this will help you
    :)

  • Use JWindow, JInternalFrame, JPanel, or JDialog

    Hello,
    My main window application extends a JFrame. When a component of the JFrame is mouse clicked,I want to open a popup window on top of this frame.
    The opened window is used to receive input from the user; with these properties: title bar, resizeable, can close with the "X" on the right side of the title bar, no minimizable or maximizable buttons on the title bar.
    1. I am very unsure whether I should use: a JWindow, JInternalFrame, JPanel, JDialog, JPopupMenu (probably not since I don't need a menu) to create the popup window. I think I should use JWindow, but am not sure.
    2. Also, I am unsure whether I can use JWindow and JInternalFrame with JFrame as the main app window.
    Thank you for your advice.

    If you want a popup window on top of this frame, you can either choose JFrame, JDialog or JWindow. They all have the own characteristics.
    JFrame: Usually application will use it as the base. Because It has a title bar with minimizable, maximizable and exit button.
    JDialog: Usually work as a option / peference / about dialog (Ex. Just click the IE about to see). Because it has a smaller title bar with only maximizable and exit button and the model setting. If model is to TRUE, that means all the other area of the window will be disable except the opened dialog own.
    JWindow: Usually use as a splash to display logo or welcome message.
    JInternalFrame: It display inside a desktop panel of JFrame. Just like the multi-documents function inside the MS Words.

  • JInternalFrame's setMaximum function is not working

    When I call setMaximum(true) on the JInternalFrame it will make the internal frame to be disappeared! Is this a bug? How can I programaticly maximize the internal frame?
    Here is the code that causes the trouble
    public class JInternalFrames extends JFrame {
    public static void main(String[] args) {
    new JInternalFrames();
    public JInternalFrames() {
    super("Multiple Document Interface");
    // WindowUtilities.setNativeLookAndFeel();
    addWindowListener(new ExitListener());
    Container content = getContentPane();
    content.setBackground(Color.white);
    JDesktopPane desktop = new JDesktopPane();
    desktop.setBackground(Color.white);
    content.add(desktop, BorderLayout.CENTER);
    setSize(450, 400);
    for(int i=0; i<5; i++) {
    JInternalFrame frame
    = new JInternalFrame(("Internal Frame " + i),
    true, true, true, true);
    frame.setLocation(i*50+10, i*50+10);
    frame.setSize(200, 150);
    frame.setBackground(Color.white);
    try {
              frame.setMaximum(true);
         } catch (PropertyVetoException e) {
         frame.setVisible(true);
    desktop.add(frame);
    frame.moveToFront();
    setVisible(true);

    Do you have any suggestion for when re-indexing doesn't work?
    our situation sounds similar. we have OSx 10.4.x as a client and OSx server 10.4.x at the server.
    Finder's find feature produces a spinning wheel. Spotlight and finder plists have been deleted.
    I have enabled spotlight on the server and can search locally and find files (presumably this means spotlight is indexing the shared volume)
    I have done this to publish indexes to the server.
    http://docs.info.apple.com/article.html?artnum=302424
    all with no apparent effect.
    Seems like there is alot of discussion regarding searching on shared volumes through out the finder discussion forum. This feature used to work then seemed to stop after the last server upgrade.
    Some of this thread seems to suggest it won't work at all.
    http://discussions.apple.com/thread.jspa?messageID=4060555&#4060555
    if this was broken by some upgrade and will get fixed in the future that's ok .. i just need to know if i am wasting my time trying to get this to work.
    Any suggestion on this problem would be appreaciated.

  • JInternalFrame inside JInternalFrame.

    Dear All,
    I must miss something, please help me to figure out.
    I have a JFrame, JDesktoppane, several JInternalFrame.
    JFrame.getContentPane().add(JDesktopPane);
    JDesktopPane.add(JInternalFrame);
    so far so good.
    Now for Created JInternalFrame ( Named as JIF1), I want to create another JInternalFrame(Named as JIF1_1) to add to JIF1.
    MyPanel extends JPanel
    MyPanel.setLayou(new BorderLayout());
    MyPanel.add(JSCollPane);
    etc......
    MyPanel map=new MyPanel();
    JDesktopPane desktopPane1_1=new JDesktopPane();
    JIF1.getContentPane().add(desktopPane1_1);
    Problem Line:desktopPane1_1.setLayout(new BorderLayout());
    ((JLayeredPane)desktopPane1_1).setLayer(map, JLayeredPane.DEFAULT_LAYER.intValue());
    JIF1_1=new JInternalFrame();
    desktopPane1_1.add(JIF1_1, JLayeredPane.PALETTE_LAYER);
    If I don't open JIF1_1, everything is OK. my JIF1 shows up with "map" panel inside, when resize JIF1, scrollbar shows also.
    NOW Open JIF1_1, run time error: desktopPane1_1 should not setLayout.
    change my code to :
    MyPanel map=new MyPanel();
    JDesktopPane desktopPane1_1=new JDesktopPane();
    JIF1.getContentPane().add(desktopPane1_1);
    REMOVE 1://Problem Line:desktopPane1_1.setLayout(new BorderLayout());
    ((JLayeredPane)desktopPane1_1).setLayer(map, JLayeredPane.DEFAULT_LAYER.intValue());
    JIF1_1=new MYJInternalFrame();
    in JIF1_1 class put
    //this method to change "map" JPanel size correctly when resize JIF1_1;
    REMOVE 2:public void paintComponent(Graphics g)
    super.paintComponent(g);          
    Rectangle mar=map.getBounds();
    Rectangle r=this.getBounds();
    int w=(int) r.getWidth();
    int h=(int) r.getHeight();
    map.setSize(new Dimension(w,h));
    map.setPreferredSize(new Dimension(w,h));
    ma.setPreferredSize(new Dimension(w,h));
    map.invalidate();
    map.validate();               
    map.repaint();          
    map.revalidate();
    map.repaint();
    desktopPane1_1.add(JIF1_1, JLayeredPane.PALETTE_LAYER);
    NOW, when I resize JIF1_1, "map" JPanel resize correctly, but my scrollbar does not show up correctly.
    If I remove REMOVE 2, put back REMOVE 1, don't open JIF1_1(Because setLayout runtime error), Scrollbar on "map" JPanel shows up when resize JIF1_1
    Since I need to open JIF1_1, revome REMOVE 1(setLayout to null instead of borderLayout), don't remove REMOVE 2, call open JIF1_1, but scrollbar on "map" JPanel does not show when resize JIF1_1.
    Please help me with this. Thank you!
    Xinman

    Never Mind, found the error!!!!! :)
    In paintComponent , need to get desktop size instead of JIF1_1 size
    Xinman

  • R U really sure JWindow's deaf?

    Hi every1,
    I'm developing a biomedical application: I've got a main frame and I would like to place
    a tiny JWindow in the middle of it as a floating toolbar.
    But neither I want any toolbar nor a new button to appear on the OS taskbar as a JFrame
    causes. I thought of a JInternalFrame, it's behaviour is the right one, but it displays a OS
    dependent top bar.
    I landed onto a JWindow. The funny thing is that, even implementing WindowListener
    interface, JWindow seems to be deaf to WindowEvents: I can't determine if it's the
    focused window or if it is activated. Whenever I click on the main frame my JWindows
    goes to back and, even though focused, it doesn't come to front any more.
    I would like to know if I can instantiate a JWindow and give it the behaviour of a JInternalFrame,
    without it to have an OS dependent top bar but only a costumized button.
    Thanx a lot
    stefano

    IMHO those youngsters are used to that silly SMS and
    chat speak, so that'sI think this is a bit of a misconception. SMS is slang not a "new language" I agree with that.
    thus it is actually a slang dialect from a particular region. In fact it is
    worse than that because SMS actually seems to devlove into a
    language that only the two people communicating can understand. I disagree with that; IMHO sms-notation was born because of the maximum
    length of the message that could be sent: 160 characters or so. People
    were quite creative in substituting single digits for an entire syllable that
    sounded similar. In the Dutch language people are over-creative with that,
    e.g. 'FF' stands for 'just a moment': 'FF' being a shortand for 'effen', (multiple effs)
    which is sort of slang for 'eventjes', which basically translates to 'just a moment'.
    Similar things happen to just phonetic parts of words (i.e. not syllables),
    i.e. 'w8' means 'wacht' ('wait' in English, the similarity is just a coincidence).
    So in SMS speak 'wait for a moment' in Dutch is translated to 'w8 FF'.
    When enough room for editing a proper text is available I find this SMS
    stuff terrible. I do think though that youngsters are more familiar with this
    type of notation and I think they will go further than I just sketched.
    kind regards,
    Jos

  • R U sure that JWindow's deaf?

    Hi every1,
    I'm developing a biomedical application: I've got a main frame and I would like to place
    a tiny JWindow in the middle of it as a floating toolbar.
    But neither I want any toolbar nor a new button to appear on the OS taskbar as a JFrame
    causes. I thought of a JInternalFrame, it's behaviour is the right one, but it displays a OS
    dependent top bar.
    I landed onto a JWindow. The funny thing is that, even implementing WindowListener
    interface, JWindow seems to be deaf to WindowEvents: I can't determine if it's the
    focused window or if it is activated. Whenever I click on the main frame my JWindows
    goes to back and, even though focused, it doesn't come to front any more.
    I would like to know if I can instantiate a JWindow and give it the behaviour of a JInternalFrame,
    without it to have an OS dependent top bar but only a costumized button.
    Thanx a lot
    stefano

    IMHO those youngsters are used to that silly SMS and
    chat speak, so that'sI think this is a bit of a misconception. SMS is slang not a "new language" I agree with that.
    thus it is actually a slang dialect from a particular region. In fact it is
    worse than that because SMS actually seems to devlove into a
    language that only the two people communicating can understand. I disagree with that; IMHO sms-notation was born because of the maximum
    length of the message that could be sent: 160 characters or so. People
    were quite creative in substituting single digits for an entire syllable that
    sounded similar. In the Dutch language people are over-creative with that,
    e.g. 'FF' stands for 'just a moment': 'FF' being a shortand for 'effen', (multiple effs)
    which is sort of slang for 'eventjes', which basically translates to 'just a moment'.
    Similar things happen to just phonetic parts of words (i.e. not syllables),
    i.e. 'w8' means 'wacht' ('wait' in English, the similarity is just a coincidence).
    So in SMS speak 'wait for a moment' in Dutch is translated to 'w8 FF'.
    When enough room for editing a proper text is available I find this SMS
    stuff terrible. I do think though that youngsters are more familiar with this
    type of notation and I think they will go further than I just sketched.
    kind regards,
    Jos

  • Openinig internal frames by clicking menuitems

    Hi,
    I have been trying to open internal frames by clicking menu items but
    have not been able to do so because menuitems support only action listeners and not all mouse event listeners.
    Actually I wanted the event to return the frame n which the event has occured
    e.g., event,getframe(), so that I could create an internal frame in the same frame.
    But such kind of function is unavailable.
    Kindly suggest something...the code is given below (it works perfectly)..it need a text file from which the menuitems are read. This is also given below:
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.*;
    import java.io.*;
    import javax.swing.plaf.metal.*;
    import javax.swing.*;
    import javax.swing.undo.*;
    class Action extends JFrame
         ActionListener FListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of File Menu was pressed.");}
        ActionListener EListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of Edit Menu was pressed.");}
        ActionListener VListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of View Menu was pressed.");}
        ActionListener TListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of Tools Menu was pressed.");}
        ActionListener HListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of Help Menu was pressed.");}
         /*     protected class MyUndoableEditListener  implements UndoableEditListener
                  protected UndoManager undo = new UndoManager();
                  public void undoableEditHappened(UndoableEditEvent e)
                 //Remember the edit and update the menus
                 undo.addEdit(e.getEdit());
                 undoAction.updateUndoState();
                 redoAction.updateRedoState();
          class framecreator extends JFrame
               public JFrame CreateFrame(JMenuBar m)
             JDesktopPane jdp= new JDesktopPane();
              JFrame.setDefaultLookAndFeelDecorated(true);       
            JFrame frame = new JFrame("PEA");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         
            frame.setContentPane(jdp);
            jdp.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);          
            frame.setJMenuBar(m);       
            frame.pack();
            frame.setVisible(true);
            frame.setSize(600,600);
            frame.setLocation(100,100);
            return frame;
          class internalframecreator extends JFrame
             public JInternalFrame CreateInternalFrame(JFrame f)
              Container cp= f.getContentPane();
              JInternalFrame jif = new JInternalFrame("internal frame",true,true,true,true);
             cp.add(jif);
             jif.pack();
             jif.setVisible(true);
             jif.setSize(300,300);
             jif.setLocation(80,80);
             return jif;    
      class menucreator
         public String[] filereader()
              String[] menuitems=new String[21];
              int i=0,j=0;
              String record = null;            
                   for(int h=0;h<21;h++){ menuitems[h]=null;}
               try { 
                    FileReader fr = new FileReader("projectconfig2.txt");  
                     BufferedReader br = new BufferedReader(fr);
                         while ( (record=br.readLine()) != null )
                           StringTokenizer st = new StringTokenizer(record,"\n");
                             while (st.hasMoreTokens())
                          menuitems= st.nextToken();
         System.out.println(menuitems[i]);
    i++;
                   /* StringTokenizer st1 = new StringTokenizer(record,"\n");
         while (st1.hasMoreTokens())
         while ( (record=br.readLine()) != null )
         StringTokenizer st2 = new StringTokenizer(record,":");
         while (st2.hasMoreTokens())
         menuitems[i][j]= st2.nextToken();
         System.out.println(menuitems[i][j]);
              j++;      
         i++;
              } catch(IOException e)
         System.out.println("Error reading file");
         return (menuitems);
         public JMenuBar CreateMenu(Action a, String menuitems[])
    JMenuBar mb = new JMenuBar();
    JMenu fileB = new JMenu(menuitems[0]);
    JMenu editB = new JMenu(menuitems[8]);
    JMenu viewB = new JMenu(menuitems[11]);
    JMenu toolsB = new JMenu(menuitems[14]);
    JMenu helpB = new JMenu(menuitems[18]);
    mb.add(fileB);
    mb.add(editB);
    mb.add(viewB);
    mb.add(toolsB);
    mb.add(helpB);
    JMenuItem newpolicyB = new JMenuItem(menuitems[1]);
    newpolicyB.addActionListener(a.FListener);
    //newpolicyB.addUndoableEditListener(new MyUndoableEditListener());
    JMenuItem openB = new JMenuItem(menuitems[2]);
    openB.addActionListener(a.FListener);
    JMenuItem saveB = new JMenuItem(menuitems[3]);
    saveB.addActionListener(a.FListener);
    JMenuItem saveasB = new JMenuItem(menuitems[4]);
    saveasB.addActionListener(a.FListener);
    JMenuItem printxmlB = new JMenuItem(menuitems[5]);
    printxmlB.addActionListener(a.FListener);
    JMenuItem printreadablepolicyB = new JMenuItem(menuitems[6]);
    printreadablepolicyB.addActionListener(a.FListener);
    JMenuItem exitB = new JMenuItem(menuitems[7]);
    exitB.addActionListener(a.FListener);
    JMenuItem undoB = new JMenuItem(menuitems[9]);
    undoB.addActionListener(a.EListener);
    JMenuItem redoB = new JMenuItem(menuitems[10]);
    redoB.addActionListener(a.EListener);
    JMenuItem xmlB = new JMenuItem(menuitems[12]);
    xmlB.addActionListener(a.VListener);
    JMenuItem readablepolicyB = new JMenuItem(menuitems[13]);
    readablepolicyB.addActionListener(a.VListener);
    JMenuItem validateB = new JMenuItem(menuitems[15]);
    validateB.addActionListener(a.TListener);
    JMenuItem signandpublishB = new JMenuItem(menuitems[16]);
    signandpublishB.addActionListener(a.TListener);
    JMenuItem optionsB = new JMenuItem(menuitems[17]);
    optionsB.addActionListener(a.TListener);
    JMenuItem pemanualB = new JMenuItem(menuitems[19]);
    pemanualB.addActionListener(a.HListener);
    JMenuItem aboutB = new JMenuItem(menuitems[20]);
    aboutB.addActionListener(a.HListener);
    fileB.add(newpolicyB);
    fileB.add(openB);
    fileB.add(saveB);
    fileB.add(saveasB);
    fileB.add(printxmlB);
    fileB.add(printreadablepolicyB);
    fileB.add(exitB);
    editB.add(undoB);
    editB.add(redoB);
    viewB.add(xmlB);
    viewB.add(readablepolicyB);
    toolsB.add(validateB);
    toolsB.add(signandpublishB);
    toolsB.add(optionsB);
    helpB.add(pemanualB);
    helpB.add(aboutB);
    mb.setSize(300,200);
    mb.setVisible(true);
    return mb;
    public class project
    public static void main(String args[])
              Action a =new Action();           
              framecreator fc=new framecreator();           
         menucreator mc=new menucreator();     
         internalframecreator ifc= new internalframecreator();          
         ifc.CreateInternalFrame(fc.CreateFrame(mc.CreateMenu(a,mc.filereader())));
    The text file called projectconfig2.txt
    File
    New Policy
    Open...
    Save
    Save As...
    Print XML
    Print Readable Policy
    Exit
    Edit
    Undo
    Redo
    View
    XML
    Readable Policy
    Tools
    Validate
    Sign & Publish
    Options
    Help
    PE Manual
    About

    The problem is that you are adding the JInternalFrame to the JFrame's contentPane when it should be added to the JDesktopPane. See your code ...
    public JInternalFrame CreateInternalFrame( JFrame  f )
         Container  cp = f.getContentPane();
         JInternalFrame jif = new JInternalFrame("internal frame",true,true,true,true);
         cp.add( jif );

  • Need to change pgm to add graphics to deskpane (desk) not the overlay panel

    Hello everybody.
    I recently had help in adding graphics to my program and I unintentionally requested that my graphics be added to a overlay panel. After further development I realized that I actually need the graphics to be painted to jdeskpane DESK. I assume that by doing this that the graphics will remain where I placed them (relative to the associated frames) when the scrollbar is utilized.
    This might be a simple question, but I am new to graphics. Once I have the answer, I will analyze it and educate my self further.
    Thank you in advance,
    BAJH
    * Copyright (c) 2007 BAH
    * All rights reserved.
    package com.newsystem.common;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.geom.Line2D;
    import java.awt.geom.Point2D;
    import java.awt.geom.Rectangle2D;
    import java.beans.PropertyVetoException;
    import javax.swing.*;
    import javax.swing.JButton;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JList;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.ListModel;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.UIManager;
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    public class A_Test_of_Frame_Connectors extends JDesktopPane {
         private static final long serialVersionUID = 1L;
         JDesktopPane desk;
         JScrollPane scrollpane;
         JInternalFrame iframe;
         JFrame frame;
         JList jList1;
         String currentframetitle;
         String currentframetip;
         String title;
         Integer maxwidth;
         Boolean definingsecondaryconnector;
         Boolean definingparentsecondaryconnector;
         Boolean definingchildsecondaryconnector;
         Rectangle secondaryparentrectangle;
         Rectangle secondarychildrectangle;
        double barb = 10.0;
        double phi = Math.toRadians(20.0);
        RenderingHints hints;
        Boolean drawline = false;
        Integer connectorcount;
        String[] connectiontype;
        String[] connectorparentframe;
        String[] connectorchildframe;
        JInternalFrame[] allframes;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHints(hints);
            g2.setPaint(Color.blue);
            if (drawline){
                  drawConnector(g2, secondaryparentrectangle, secondarychildrectangle);
        private void drawConnector(Graphics2D g2,Rectangle r1,Rectangle r2) {
            double dx = r2.getCenterX() - r1.getCenterX();
            double dy = r2.getCenterY() - r1.getCenterY();
            double theta = Math.atan2(dy, dx);
            Point2D.Double p1 = getIntersectionPoint(r1, theta);
            Point2D.Double p2 = getIntersectionPoint(r2, theta+Math.PI);
            Line2D.Double line = new Line2D.Double(p1, p2);
            drawArrowHeads(line, g2);
            g2.draw(line);
         public A_Test_of_Frame_Connectors(){
            hints = new RenderingHints(null);
            hints.put(RenderingHints.KEY_ANTIALIASING,
                      RenderingHints.VALUE_ANTIALIAS_ON);
            hints.put(RenderingHints.KEY_STROKE_CONTROL,
                      RenderingHints.VALUE_STROKE_PURE);
              definingsecondaryconnector = false;
              frame = new JFrame("All Frames in a JDesktopPane Container");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              scrollpane = new JScrollPane(desk,
                        ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
              scrollpane.setPreferredSize(new java.awt.Dimension(9925, 9580));
              desk = new JDesktopPane();
              desk.setPreferredSize(new java.awt.Dimension(15000, 30000));
                   int i = 5;
                   for (int j = 1; j <= i; j++){
                        UIManager.getDefaults().put("InternalFrame.icon", "");
                             ListModel jList1Model =
                                  new DefaultComboBoxModel(
                                            new String[] { "Item One" });
                             title = "Frame " + j;
                             jList1 = new JList();
                             jList1.setModel(jList1Model);
                        jList1.setBounds(1, 1, 45, 54);
                        jList1.setEnabled(false);
                        iframe = new JInternalFrame("Internal Frame: " + j, false, false, false, false);
                        iframe.setName(String.valueOf(j));
                        iframe.setTitle(title);
                        Integer titlewidth;
                        if (title.length() < 30){
                             titlewidth = 265;
                        else{
                             titlewidth = title.length()*8 + 20;
                        iframe.setBounds(j*20, j*20,titlewidth , j*18 + 35);
                        iframe.add(jList1);
                        iframe.addInternalFrameListener(new InternalFrameListener(){
                             public void internalFrameClosing(InternalFrameEvent e) {}
                             public void internalFrameClosed(InternalFrameEvent e) {}
                             public void internalFrameOpened(InternalFrameEvent e) {}
                             public void internalFrameIconified(InternalFrameEvent e) {}
                             public void internalFrameDeiconified(InternalFrameEvent e) {}
                             public void internalFrameActivated(InternalFrameEvent e) {
                                  currentframetitle = e.getInternalFrame().getTitle();
                                  currentframetip = e.getInternalFrame().getToolTipText();
                                  // Connectors
                                  if (definingsecondaryconnector.equals(true)){
                                       if (definingparentsecondaryconnector.equals(true)){
                                            // Build dummy rectangle for creating connector                         
                                            secondaryparentrectangle = new Rectangle(e.getInternalFrame().getBounds());
                                            System.out.println("f name - "+e.getInternalFrame().getName());
                                            definingparentsecondaryconnector = false;
                                            definingchildsecondaryconnector = true;
                                       } else {
                                       if (definingchildsecondaryconnector.equals(true)){
                                            // Build dummy rectangle for creating connector                         
                                            secondarychildrectangle = new Rectangle(e.getInternalFrame().getBounds());
                                            // draw connector
                                               drawline = true;
                                               repaint();
                                               definingchildsecondaryconnector = false;
                             public void internalFrameDeactivated(InternalFrameEvent e) {}
                        iframe.setToolTipText("Internal Frame :" + j);
                        iframe.setVisible(true);
                        desk.add(iframe);
              scrollpane.setViewportView(desk);
              JMenuBar menubar = new JMenuBar();
              JButton SecondaryConnector = new JButton("Secondary Connector");
              SecondaryConnector.addMouseListener(new java.awt.event.MouseAdapter() {
                   public void mousePressed(java.awt.event.MouseEvent e) {
                        definingsecondaryconnector = true;
                        definingparentsecondaryconnector = true;
                        definingchildsecondaryconnector = false;                    
                        try {
                             desk.getSelectedFrame().setSelected(false);
                        } catch (PropertyVetoException e1) {
                             // TODO Auto-generated catch block
                             e1.printStackTrace();
              JPanel overlayPanel = new JPanel();
                 OverlayLayout overlay = new OverlayLayout(overlayPanel);
                 overlayPanel.setLayout(overlay);
                 this.setOpaque(false);
                 overlayPanel.add(this);
                 overlayPanel.add(scrollpane);
              menubar.add(SecondaryConnector);
              frame.setJMenuBar(menubar);
    //          frame.add(scrollpane);
              frame.add(overlayPanel);
              scrollpane.setVisible(true);
              frame.setSize(800,600);
              frame.setVisible(true);
        private Point2D.Double getIntersectionPoint(Rectangle r, double theta) {
            double cx = r.getCenterX();
            double cy = r.getCenterY();
            double w = r.getWidth()/2;
            double h = r.getHeight()/2;
            double radius = Point2D.distance(0,0,w,h);
            double x = cx + radius * Math.cos(theta);
            double y = cy + radius * Math.sin(theta);
            Point2D.Double p = new Point2D.Double();
            int outcode = r.outcode(x, y);
            switch(outcode) {
                case Rectangle2D.OUT_TOP:             // 2
                    p.x = cx - h*((x - cx)/(y - cy));
                    p.y = cy - h;
                    break;
                case Rectangle2D.OUT_LEFT:            // 1
                    p.x = cx - w;
                    p.y = cy - w*((y - cy)/(x - cx));
                    break;
                case Rectangle2D.OUT_BOTTOM:          // 8
                    p.x = cx + h*((x - cx)/(y - cy));
                    p.y = cy + h;
                    break;
                case Rectangle2D.OUT_RIGHT:           // 4
                    p.x = cx + w;
                    p.y = cy + w*((y - cy)/(x - cx));
                    break;
                default:
                    System.out.println("Non-cardinal outcode: " + outcode);
            return p;
        private void drawArrowHeads(Line2D.Double line, Graphics2D g2) {
            double dy = line.getY2() - line.getY1();
            double dx = line.getX2() - line.getX1();
            double theta = Math.atan2(dy, dx);
            drawArrowHead(line.getP2(), theta, g2);
            drawArrowHead(line.getP1(), theta+Math.PI, g2);
        private void drawArrowHead(Point2D tip, double theta, Graphics2D g2) {
            double x = tip.getX() - barb * Math.cos(theta+phi);
            double y = tip.getY() - barb * Math.sin(theta+phi);
            g2.draw(new Line2D.Double(tip.getX(), tip.getY(), x, y));
            x = tip.getX() - barb * Math.cos(theta-phi);
            y = tip.getY() - barb * Math.sin(theta-phi);
            g2.draw(new Line2D.Double(tip.getX(), tip.getY(), x, y));
         public static void main(String[] args) {
              A_Test_of_Frame_Connectors d = new A_Test_of_Frame_Connectors();
    }

    Hello everybody.
    I recently had help in adding graphics to my program and I unintentionally requested that my graphics be added to a overlay panel. After further development I realized that I actually need the graphics to be painted to jdeskpane DESK. I assume that by doing this that the graphics will remain where I placed them (relative to the associated frames) when the scrollbar is utilized.
    This might be a simple question, but I am new to graphics. Once I have the answer, I will analyze it and educate my self further.
    Thank you in advance,
    BAJH
    * Copyright (c) 2007 BAH
    * All rights reserved.
    package com.newsystem.common;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.geom.Line2D;
    import java.awt.geom.Point2D;
    import java.awt.geom.Rectangle2D;
    import java.beans.PropertyVetoException;
    import javax.swing.*;
    import javax.swing.JButton;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JList;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.ListModel;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.UIManager;
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    public class A_Test_of_Frame_Connectors extends JDesktopPane {
         private static final long serialVersionUID = 1L;
         JDesktopPane desk;
         JScrollPane scrollpane;
         JInternalFrame iframe;
         JFrame frame;
         JList jList1;
         String currentframetitle;
         String currentframetip;
         String title;
         Integer maxwidth;
         Boolean definingsecondaryconnector;
         Boolean definingparentsecondaryconnector;
         Boolean definingchildsecondaryconnector;
         Rectangle secondaryparentrectangle;
         Rectangle secondarychildrectangle;
        double barb = 10.0;
        double phi = Math.toRadians(20.0);
        RenderingHints hints;
        Boolean drawline = false;
        Integer connectorcount;
        String[] connectiontype;
        String[] connectorparentframe;
        String[] connectorchildframe;
        JInternalFrame[] allframes;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHints(hints);
            g2.setPaint(Color.blue);
            if (drawline){
                  drawConnector(g2, secondaryparentrectangle, secondarychildrectangle);
        private void drawConnector(Graphics2D g2,Rectangle r1,Rectangle r2) {
            double dx = r2.getCenterX() - r1.getCenterX();
            double dy = r2.getCenterY() - r1.getCenterY();
            double theta = Math.atan2(dy, dx);
            Point2D.Double p1 = getIntersectionPoint(r1, theta);
            Point2D.Double p2 = getIntersectionPoint(r2, theta+Math.PI);
            Line2D.Double line = new Line2D.Double(p1, p2);
            drawArrowHeads(line, g2);
            g2.draw(line);
         public A_Test_of_Frame_Connectors(){
            hints = new RenderingHints(null);
            hints.put(RenderingHints.KEY_ANTIALIASING,
                      RenderingHints.VALUE_ANTIALIAS_ON);
            hints.put(RenderingHints.KEY_STROKE_CONTROL,
                      RenderingHints.VALUE_STROKE_PURE);
              definingsecondaryconnector = false;
              frame = new JFrame("All Frames in a JDesktopPane Container");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              scrollpane = new JScrollPane(desk,
                        ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
              scrollpane.setPreferredSize(new java.awt.Dimension(9925, 9580));
              desk = new JDesktopPane();
              desk.setPreferredSize(new java.awt.Dimension(15000, 30000));
                   int i = 5;
                   for (int j = 1; j <= i; j++){
                        UIManager.getDefaults().put("InternalFrame.icon", "");
                             ListModel jList1Model =
                                  new DefaultComboBoxModel(
                                            new String[] { "Item One" });
                             title = "Frame " + j;
                             jList1 = new JList();
                             jList1.setModel(jList1Model);
                        jList1.setBounds(1, 1, 45, 54);
                        jList1.setEnabled(false);
                        iframe = new JInternalFrame("Internal Frame: " + j, false, false, false, false);
                        iframe.setName(String.valueOf(j));
                        iframe.setTitle(title);
                        Integer titlewidth;
                        if (title.length() < 30){
                             titlewidth = 265;
                        else{
                             titlewidth = title.length()*8 + 20;
                        iframe.setBounds(j*20, j*20,titlewidth , j*18 + 35);
                        iframe.add(jList1);
                        iframe.addInternalFrameListener(new InternalFrameListener(){
                             public void internalFrameClosing(InternalFrameEvent e) {}
                             public void internalFrameClosed(InternalFrameEvent e) {}
                             public void internalFrameOpened(InternalFrameEvent e) {}
                             public void internalFrameIconified(InternalFrameEvent e) {}
                             public void internalFrameDeiconified(InternalFrameEvent e) {}
                             public void internalFrameActivated(InternalFrameEvent e) {
                                  currentframetitle = e.getInternalFrame().getTitle();
                                  currentframetip = e.getInternalFrame().getToolTipText();
                                  // Connectors
                                  if (definingsecondaryconnector.equals(true)){
                                       if (definingparentsecondaryconnector.equals(true)){
                                            // Build dummy rectangle for creating connector                         
                                            secondaryparentrectangle = new Rectangle(e.getInternalFrame().getBounds());
                                            System.out.println("f name - "+e.getInternalFrame().getName());
                                            definingparentsecondaryconnector = false;
                                            definingchildsecondaryconnector = true;
                                       } else {
                                       if (definingchildsecondaryconnector.equals(true)){
                                            // Build dummy rectangle for creating connector                         
                                            secondarychildrectangle = new Rectangle(e.getInternalFrame().getBounds());
                                            // draw connector
                                               drawline = true;
                                               repaint();
                                               definingchildsecondaryconnector = false;
                             public void internalFrameDeactivated(InternalFrameEvent e) {}
                        iframe.setToolTipText("Internal Frame :" + j);
                        iframe.setVisible(true);
                        desk.add(iframe);
              scrollpane.setViewportView(desk);
              JMenuBar menubar = new JMenuBar();
              JButton SecondaryConnector = new JButton("Secondary Connector");
              SecondaryConnector.addMouseListener(new java.awt.event.MouseAdapter() {
                   public void mousePressed(java.awt.event.MouseEvent e) {
                        definingsecondaryconnector = true;
                        definingparentsecondaryconnector = true;
                        definingchildsecondaryconnector = false;                    
                        try {
                             desk.getSelectedFrame().setSelected(false);
                        } catch (PropertyVetoException e1) {
                             // TODO Auto-generated catch block
                             e1.printStackTrace();
              JPanel overlayPanel = new JPanel();
                 OverlayLayout overlay = new OverlayLayout(overlayPanel);
                 overlayPanel.setLayout(overlay);
                 this.setOpaque(false);
                 overlayPanel.add(this);
                 overlayPanel.add(scrollpane);
              menubar.add(SecondaryConnector);
              frame.setJMenuBar(menubar);
    //          frame.add(scrollpane);
              frame.add(overlayPanel);
              scrollpane.setVisible(true);
              frame.setSize(800,600);
              frame.setVisible(true);
        private Point2D.Double getIntersectionPoint(Rectangle r, double theta) {
            double cx = r.getCenterX();
            double cy = r.getCenterY();
            double w = r.getWidth()/2;
            double h = r.getHeight()/2;
            double radius = Point2D.distance(0,0,w,h);
            double x = cx + radius * Math.cos(theta);
            double y = cy + radius * Math.sin(theta);
            Point2D.Double p = new Point2D.Double();
            int outcode = r.outcode(x, y);
            switch(outcode) {
                case Rectangle2D.OUT_TOP:             // 2
                    p.x = cx - h*((x - cx)/(y - cy));
                    p.y = cy - h;
                    break;
                case Rectangle2D.OUT_LEFT:            // 1
                    p.x = cx - w;
                    p.y = cy - w*((y - cy)/(x - cx));
                    break;
                case Rectangle2D.OUT_BOTTOM:          // 8
                    p.x = cx + h*((x - cx)/(y - cy));
                    p.y = cy + h;
                    break;
                case Rectangle2D.OUT_RIGHT:           // 4
                    p.x = cx + w;
                    p.y = cy + w*((y - cy)/(x - cx));
                    break;
                default:
                    System.out.println("Non-cardinal outcode: " + outcode);
            return p;
        private void drawArrowHeads(Line2D.Double line, Graphics2D g2) {
            double dy = line.getY2() - line.getY1();
            double dx = line.getX2() - line.getX1();
            double theta = Math.atan2(dy, dx);
            drawArrowHead(line.getP2(), theta, g2);
            drawArrowHead(line.getP1(), theta+Math.PI, g2);
        private void drawArrowHead(Point2D tip, double theta, Graphics2D g2) {
            double x = tip.getX() - barb * Math.cos(theta+phi);
            double y = tip.getY() - barb * Math.sin(theta+phi);
            g2.draw(new Line2D.Double(tip.getX(), tip.getY(), x, y));
            x = tip.getX() - barb * Math.cos(theta-phi);
            y = tip.getY() - barb * Math.sin(theta-phi);
            g2.draw(new Line2D.Double(tip.getX(), tip.getY(), x, y));
         public static void main(String[] args) {
              A_Test_of_Frame_Connectors d = new A_Test_of_Frame_Connectors();
    }

  • How do I modify a specific component within a active internalframe?

    I need to change an icon (toggle like) on a button within an internal frame when it is pressed.. I know what the active frame is. How do I address the specific component (wiithin a deskpane within a internalframe)?
    Thank you in advance,
    BAJH

    Here is a stripped down version of the program:
    i
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.OverlayLayout;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.UIManager;
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    public class TestFrameButton extends JDesktopPane{
         private static final long serialVersionUID = 1L;
         JDesktopPane desk;
         JDesktopPane ifdesk;
         JScrollPane scrollpane;
         JInternalFrame iframe;
         JFrame frame;
         JList jList1;
         JInternalFrame currentframe;
         Integer currentframenumber;
         String currentframename;
         Boolean[] downuptracker;
         Integer deskwidth = 1000;
         Integer deskheight = 1000;
         Integer scrollwidth = 1000;
         Integer scrollheight = 1000;
         JButton DownUpButton;
         public static void main(String[] args) {
              TestFrameButton d = new TestFrameButton();
         public TestFrameButton(){
              downuptracker = new Boolean [99];
              frame = new JFrame("Test Frame Button");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              scrollpane = new JScrollPane(desk,
                        ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
              scrollpane.setPreferredSize(new java.awt.Dimension(scrollwidth, scrollheight));
              desk = new JDesktopPane();
              desk.setPreferredSize(new java.awt.Dimension(deskwidth, deskheight));
              int i = 5;
              for (int j = 0; j <= i; j++){
                   UIManager.getDefaults().put("InternalFrame.icon", "");
                   iframe = new JInternalFrame("Internal Frame: " + j, false, true, false, false);
                   iframe.setName(String.valueOf(j));
                   iframe.setBounds(30*j, 30*j,265 , 80);
                   iframe.addInternalFrameListener(new InternalFrameListener(){
                        public void internalFrameClosing(InternalFrameEvent e) {
                        public void internalFrameClosed(InternalFrameEvent e) {
                        public void internalFrameOpened(InternalFrameEvent e) {
                        public void internalFrameIconified(InternalFrameEvent e) {
                        public void internalFrameDeiconified(InternalFrameEvent e) {
                        public void internalFrameActivated(InternalFrameEvent e) {
                             currentframe = e.getInternalFrame();
                             currentframename = e.getInternalFrame().getName();
                             currentframenumber = Integer.valueOf(currentframename);
                        public void internalFrameDeactivated(InternalFrameEvent e) {
                   iframe.setTitle("Internal Frame :" + j);
                   iframe.setVisible(true);
                   downuptracker[j] = true;
                   ifdesk = new JDesktopPane();
                   iframe.getContentPane().add(ifdesk, BorderLayout.CENTER);
                   DownUpButton = new JButton("Old Icon here");
                   ifdesk.add(DownUpButton);
                   DownUpButton.setBounds(0, 0, 130, 20);
                   DownUpButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             if (downuptracker[currentframenumber].equals(true)){
                                  // Colapse frame here and change icon
                                  DownUpButton.setText("New Icon here");
                                  downuptracker[currentframenumber] = false;
                             }else{
                                  // Expand frame here and change icon
                                  DownUpButton.setText("Old Icon here");
                                  downuptracker[currentframenumber] = true;
                   desk.add(iframe);
                   iframe.moveToFront();
              scrollpane.setViewportView(desk);
              JPanel overlayPanel = new JPanel();
              OverlayLayout overlay = new OverlayLayout(overlayPanel);
              overlayPanel.setLayout(overlay);
              this.setOpaque(false);
              desk.setOpaque(true);
              overlayPanel.add(this);
              overlayPanel.add(scrollpane);
              frame.add(overlayPanel);
              scrollpane.setVisible(true);
              frame.setSize(800,600);
              frame.setVisible(true);
    }Thank you in advance,
    BAJH - I will never multi-post again!

  • Performance of JEditorPane with unicode characters

    Hi,
    I'm using a JEditorPane to edit rather large (> 15000 words) but simple HTML files. Everyting is fine until I add even a single unicode character to the text with a character code higher than 255, like a Greek omega (\u03A9). With the unicode character the control starts to take an incredibly long time to redraw (sometimes minutes) when you resize it, for instance. The strangest thing is that removing the character again does not restore performance. Can anyone explain why this is happening?
    import javax.swing.*;
    import javax.swing.text.html.HTMLEditorKit;
    public class EditorPaneTest {
    public static void main(String[] args) {
    StringBuffer html = new StringBuffer();
    html.append("<html><body>");
    // Uncomment next line, run and resize frame to see problem
    // html.append("<p>\u03A9</p>");
    for (int i = 0; i < 2000; i++) {
    html.append("<p>Testing, testing, testing...</p>");
    html.append("</body></html>");
    JFrame jFrame = new JFrame("Test");
    jFrame.setSize(300, 300);
    JEditorPane jEditorPane = new JEditorPane();
    jEditorPane.setEditorKit(new HTMLEditorKit());
    jFrame.add(new JScrollPane(jEditorPane));
    jFrame.setDefaultCloseOperation(JInternalFrame.EXIT_ON_CLOSE);
    jFrame.setVisible(true);
    jEditorPane.setText(html.toString());
    }Any help would be much appreciated.
    Thanks,
    Rasmus

    In the meantime, I had to solve my problem one way or another, and the only thing that came up to my mind was to use JavaMail API.
    It is not quite what I was hoping for, because it doesn't provide opening of default e-mail client on local machine, but at least it can send e-mail with Unicode characters in the subjects line, recipient addresses, etc.
    Make a new message using JavaMail and then set it's properties in a fairly simple manner, like this:
    message.setSubject( MimeUtility.encodeText("+ ... some Unicode text with Cyrillic symbols ... +", "UTF-8", "B") );I'd still like to see if there are any suggestions on how to do the similar thing with java.awt.Desktop.
    Regards,
    PS

  • My Free Java Print Preview Class

    Ok, for 2 weeks now ive been in agony trying to program a
    print preview for a program im writing for work.
    Alot, of the free print previews online are way complicated
    and crazy and hard to implement.
    Either that, or these forums and "how tos" online never
    answered the question or were to general or hard
    to follow for a beginner.
    I even posted a $40 question on google answers on how to
    do this and never got an answer.
    If ive had this problem others must have also
    so to save them the trouble i went through, here is a good
    starting point.
    I just finished this class.
    All you have to do is pass it a JPanel (or i guess any component
    with a " .paint(Graphics g) " ).
    new PrintPreview( component );all you might have to change is JInternalFrame to JFrame which is
    easy. also, the fit to page doesnt work yet but thats easy to code.
    please, i encourage comments and polite criticism.
    im just starting out so i know this isnt perfect but i posted
    it with good intentions.
    Hope it helps out some out there.
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import java.lang.Math.*;
    import java.awt.image.*;
    public class PrintPreview extends JInternalFrame implements ActionListener{
    public PrintPreview(Component pc){
         super("Print Preview", true, true, true, true);
         PC = pc;
    // buttons
         pf1 = new JRadioButton("Portrait");
            pf1.setActionCommand("1");
            pf1.setSelected(true);
            pf2 = new JRadioButton("Landscape");
            pf2.setActionCommand("2");
            pf.add(pf1);
            pf.add(pf2);
            pf1.setBackground(Pref.tbgc);
            pf2.setBackground(Pref.tbgc);
            cp.setBackground(Pref.tbgc);
         preview.addActionListener(this);
            print.addActionListener(this);
    // set
         pp.setPreferredSize(new Dimension(460, 460));
         pp.setBorder(BorderFactory.createLineBorder (Color.black, 2));
         pp.setBackground(Pref.tbgc);
         hold.setPreferredSize(new Dimension(200, 280));
         hold.setBorder(BorderFactory.createLineBorder (Color.black, 2));
         hold.setBackground(Pref.tbgc);
    // make main panel
         mp.setBackground(Pref.tbgc);
         GridBagLayout gridbag = new GridBagLayout();
         GridBagConstraints constraints = new GridBagConstraints();
         mp.setLayout(gridbag);
    // make hold panel
         GridBagLayout g1 = new GridBagLayout();
         GridBagConstraints c1 = new GridBagConstraints();
         hold.setLayout(g1);
    // DELETE
         PF.setOrientation(PF.PORTRAIT);
    // GUI
    // hold
         c1.insets.top = 5;
         c1.insets.left = 45;
         c1.insets.right = 5;
         buildConstraints(c1, 0, 2, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(pf1, c1);
         hold.add(pf1);
         c1.insets.top = 2;
         buildConstraints(c1, 0, 4, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(pf2, c1);
         hold.add(pf2);
         c1.insets.left = 5;
         c1.insets.right = 0;
         c1.insets.top = 25;
         buildConstraints(c1, 0, 6, 1, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(xsl, c1);
         hold.add(xsl);
         c1.insets.left = 0;
         c1.insets.right = 5;
         buildConstraints(c1, 1, 6, 1, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(xs, c1);
         hold.add(xs);
         c1.insets.left = 5;
         c1.insets.right = 0;
         c1.insets.top = 5;
         buildConstraints(c1, 0, 8, 1, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(ysl, c1);
         hold.add(ysl);
         c1.insets.left = 0;
         c1.insets.right = 5;
         buildConstraints(c1, 1, 8, 1, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(ys, c1);
         hold.add(ys);
         c1.insets.left = 25;
         c1.insets.right = 5;
         buildConstraints(c1, 0, 10, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(cp, c1);
         hold.add(cp);
         c1.insets.left = 35;
         c1.insets.right = 35;
         c1.insets.top = 20;
         buildConstraints(c1, 0, 12, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(ftp, c1);
         hold.add(ftp);
         c1.insets.left = 35;
         c1.insets.right = 35;
         c1.insets.top = 25;
         buildConstraints(c1, 0, 14, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(preview, c1);
         hold.add(preview);
         c1.insets.bottom = 15;
         c1.insets.top = 5;
         buildConstraints(c1, 0, 16, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(print, c1);
         hold.add(print);
         constraints.insets.top = 10;
         constraints.insets.left = 10;
         constraints.insets.bottom = 10;
         buildConstraints(constraints, 0, 2, 1, 1, 1, 1);
         constraints.fill = GridBagConstraints.NONE;
         gridbag.setConstraints(hold, constraints);
         mp.add(hold);
         constraints.insets.right = 10;
         buildConstraints(constraints, 1, 2, 1, 1, 1, 1);
         constraints.fill = GridBagConstraints.NONE;
         gridbag.setConstraints(pp, constraints);
         mp.add(pp);
    // display
         this.setContentPane(mp);
         this.setVisible(true);
         this.setResizable(false);
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         setSize(720, 520);
            Dimension windowSize = getSize();
         setLocation(Math.max(0,(screenSize.width -windowSize.width)/2),
            (Math.max(0,(screenSize.height-windowSize.height)/2)));
            DESKTOP.desktop.add(this);
            try {
         this.setSelected(true);
            } catch (java.beans.PropertyVetoException e) {}
    public void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, double wx, double wy){
         gbc.gridx = gx;
         gbc.gridy = gy;
         gbc.gridwidth = gw;
         gbc.gridheight = gh;
         gbc.weightx = wx;
         gbc.weighty = wy;
    public class PreviewPage extends JPanel{
    public PreviewPage(){
    public void paint(Graphics g){
         super.paint(g);
         Graphics2D g2 = (Graphics2D)g;
    // PORTRAIT
         if(PF.getOrientation() == PF.PORTRAIT){
         g.setColor(Color.black);
         g.drawRect(60, 10, 340, 440);
         int x1 = (int)Math.rint( ( (double)PF.getImageableX() / 72 ) * 40 );
         int y1 = (int)Math.rint( ( (double)PF.getImageableY() / 72 ) * 40 );
         int l1 = (int)Math.rint( ( (double)PF.getImageableWidth() / 72 ) * 40 );
         int h1 = (int)Math.rint( ( (double)PF.getImageableHeight() / 72 ) * 40 );
         g.setColor(Color.red);
         g.drawRect(x1+60, y1+10, l1, h1);
         setScales();
         int x2 = (int)Math.rint( 1028 / XSC );
         int y2 = (int)Math.rint( 768 / YSC );
         Image image = new BufferedImage( x2, y2, BufferedImage.TYPE_INT_ARGB);
         PC.paint( image.getGraphics() );
         g.drawImage(image, x1+60, y1+10, l1, h1, this);
    // LANDSCAPE
         if(PF.getOrientation() == PF.LANDSCAPE){
         g.setColor(Color.black);
         g.drawRect(10, 60, 440, 340);
         int x1 = (int)Math.rint( ( (double)PF.getImageableX() / 72 ) * 40 );
         int y1 = (int)Math.rint( ( (double)PF.getImageableY() / 72 ) * 40 );
         int l1 = (int)Math.rint( ( (double)PF.getImageableWidth() / 72 ) * 40 );
         int h1 = (int)Math.rint( ( (double)PF.getImageableHeight() / 72 ) * 40 );
         g.setColor(Color.red);
         g.drawRect(x1+10, y1+60, l1, h1);
         setScales();
         int x2 = (int)Math.rint( 1028 / XSC );
         int y2 = (int)Math.rint( 768 / YSC );
         Image image = new BufferedImage( x2, y2, BufferedImage.TYPE_INT_ARGB);
         PC.paint( image.getGraphics() );
         g.drawImage(image, x1+10, y1+60, l1, h1, this);
    public void actionPerformed(ActionEvent e){
    // fit to page
         if(e.getSource() == ftp){
    // preview
         if(e.getSource() == preview){
         setProperties();
    // print
         if(e.getSource() == print){
         doPrint();
    public void setProperties(){
         if(pf1.isSelected() == true){
         PF.setOrientation(PF.PORTRAIT);
         if(pf2.isSelected() == true){
         PF.setOrientation(PF.LANDSCAPE);
         setScales();
         pp.repaint();
    public void setScales(){
         try{
         XSC = Double.parseDouble( xs.getText() );
         } catch (NumberFormatException e) { }
         try{
         YSC = Double.parseDouble( ys.getText() );
         } catch (NumberFormatException e) { }
    public void doPrint(){
         PrintThis();
    public void PrintThis(){
         PrinterJob printerJob = PrinterJob.getPrinterJob();
         Book book = new Book();
         book.append( new PrintPage(), PF );
         printerJob.setPageable(book);
         boolean doPrint = printerJob.printDialog();
         if (doPrint) {
         try {
         printerJob.print();
         } catch (PrinterException exception) {
         System.err.println("Printing error: " + exception);
    public class PrintPage implements Printable{
    public int print(Graphics g, PageFormat format, int pageIndex) {
         Graphics2D g2D = (Graphics2D) g;
         g2D.translate(format.getImageableX (), format.getImageableY ());
         disableDoubleBuffering(mp);
         System.out.println("get i x " + format.getImageableX ());
         System.out.println("get i x " + format.getImageableY ());
         System.out.println("getx: " + format.getImageableWidth() );
         System.out.println("getx: " + format.getImageableHeight() );
         // scale to fill the page
         double dw = format.getImageableWidth();
         double dh = format.getImageableHeight();
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         setScales();
         double xScale = dw / (1028/XSC);
         double yScale = dh / (768/YSC);
         double scale = Math.min(xScale,yScale);
         System.out.println("" + scale);
         g2D.scale( xScale, yScale);
         ((JPanel)PC).paint(g);
         enableDoubleBuffering(mp);
         return Printable.PAGE_EXISTS;
    public void disableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(false);
    public void enableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(true);
         Component PC;
         PageFormat PF = new PageFormat();
         double XSC = 1;
         double YSC = 1;
    // gui comp
         JPanel mp = new JPanel();
         JPanel hold = new JPanel();
         JPanel pp = new PreviewPage();
         ButtonGroup pf = new ButtonGroup();
         JRadioButton pf1;
         JRadioButton pf2;
         JLabel xsl = new JLabel("X Scale:", JLabel.LEFT);
         JTextField xs = new JTextField("1");
         JLabel ysl = new JLabel("Y Scale:", JLabel.LEFT);
         JTextField ys = new JTextField("1");
         JButton ftp = new JButton("Fit to Page");
         JCheckBox cp = new JCheckBox("Constrain Proportions");
         JButton preview = new JButton("PREVIEW");
         JButton print = new JButton("PRINT");
    }

    Ok, for 2 weeks now ive been in agony trying to program a
    print preview for a program im writing for work.
    Alot, of the free print previews online are way complicated
    and crazy and hard to implement.
    Either that, or these forums and "how tos" online never
    answered the question or were to general or hard
    to follow for a beginner.
    I even posted a $40 question on google answers on how to
    do this and never got an answer.
    If ive had this problem others must have also
    so to save them the trouble i went through, here is a good
    starting point.
    I just finished this class.
    All you have to do is pass it a JPanel (or i guess any component
    with a " .paint(Graphics g) " ).
    new PrintPreview( component );all you might have to change is JInternalFrame to JFrame which is
    easy. also, the fit to page doesnt work yet but thats easy to code.
    please, i encourage comments and polite criticism.
    im just starting out so i know this isnt perfect but i posted
    it with good intentions.
    Hope it helps out some out there.
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import java.lang.Math.*;
    import java.awt.image.*;
    public class PrintPreview extends JInternalFrame implements ActionListener{
    public PrintPreview(Component pc){
         super("Print Preview", true, true, true, true);
         PC = pc;
    // buttons
         pf1 = new JRadioButton("Portrait");
            pf1.setActionCommand("1");
            pf1.setSelected(true);
            pf2 = new JRadioButton("Landscape");
            pf2.setActionCommand("2");
            pf.add(pf1);
            pf.add(pf2);
            pf1.setBackground(Pref.tbgc);
            pf2.setBackground(Pref.tbgc);
            cp.setBackground(Pref.tbgc);
         preview.addActionListener(this);
            print.addActionListener(this);
    // set
         pp.setPreferredSize(new Dimension(460, 460));
         pp.setBorder(BorderFactory.createLineBorder (Color.black, 2));
         pp.setBackground(Pref.tbgc);
         hold.setPreferredSize(new Dimension(200, 280));
         hold.setBorder(BorderFactory.createLineBorder (Color.black, 2));
         hold.setBackground(Pref.tbgc);
    // make main panel
         mp.setBackground(Pref.tbgc);
         GridBagLayout gridbag = new GridBagLayout();
         GridBagConstraints constraints = new GridBagConstraints();
         mp.setLayout(gridbag);
    // make hold panel
         GridBagLayout g1 = new GridBagLayout();
         GridBagConstraints c1 = new GridBagConstraints();
         hold.setLayout(g1);
    // DELETE
         PF.setOrientation(PF.PORTRAIT);
    // GUI
    // hold
         c1.insets.top = 5;
         c1.insets.left = 45;
         c1.insets.right = 5;
         buildConstraints(c1, 0, 2, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(pf1, c1);
         hold.add(pf1);
         c1.insets.top = 2;
         buildConstraints(c1, 0, 4, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(pf2, c1);
         hold.add(pf2);
         c1.insets.left = 5;
         c1.insets.right = 0;
         c1.insets.top = 25;
         buildConstraints(c1, 0, 6, 1, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(xsl, c1);
         hold.add(xsl);
         c1.insets.left = 0;
         c1.insets.right = 5;
         buildConstraints(c1, 1, 6, 1, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(xs, c1);
         hold.add(xs);
         c1.insets.left = 5;
         c1.insets.right = 0;
         c1.insets.top = 5;
         buildConstraints(c1, 0, 8, 1, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(ysl, c1);
         hold.add(ysl);
         c1.insets.left = 0;
         c1.insets.right = 5;
         buildConstraints(c1, 1, 8, 1, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(ys, c1);
         hold.add(ys);
         c1.insets.left = 25;
         c1.insets.right = 5;
         buildConstraints(c1, 0, 10, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(cp, c1);
         hold.add(cp);
         c1.insets.left = 35;
         c1.insets.right = 35;
         c1.insets.top = 20;
         buildConstraints(c1, 0, 12, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(ftp, c1);
         hold.add(ftp);
         c1.insets.left = 35;
         c1.insets.right = 35;
         c1.insets.top = 25;
         buildConstraints(c1, 0, 14, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(preview, c1);
         hold.add(preview);
         c1.insets.bottom = 15;
         c1.insets.top = 5;
         buildConstraints(c1, 0, 16, 2, 1, 1, 1);
         c1.fill = GridBagConstraints.BOTH;
         g1.setConstraints(print, c1);
         hold.add(print);
         constraints.insets.top = 10;
         constraints.insets.left = 10;
         constraints.insets.bottom = 10;
         buildConstraints(constraints, 0, 2, 1, 1, 1, 1);
         constraints.fill = GridBagConstraints.NONE;
         gridbag.setConstraints(hold, constraints);
         mp.add(hold);
         constraints.insets.right = 10;
         buildConstraints(constraints, 1, 2, 1, 1, 1, 1);
         constraints.fill = GridBagConstraints.NONE;
         gridbag.setConstraints(pp, constraints);
         mp.add(pp);
    // display
         this.setContentPane(mp);
         this.setVisible(true);
         this.setResizable(false);
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         setSize(720, 520);
            Dimension windowSize = getSize();
         setLocation(Math.max(0,(screenSize.width -windowSize.width)/2),
            (Math.max(0,(screenSize.height-windowSize.height)/2)));
            DESKTOP.desktop.add(this);
            try {
         this.setSelected(true);
            } catch (java.beans.PropertyVetoException e) {}
    public void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, double wx, double wy){
         gbc.gridx = gx;
         gbc.gridy = gy;
         gbc.gridwidth = gw;
         gbc.gridheight = gh;
         gbc.weightx = wx;
         gbc.weighty = wy;
    public class PreviewPage extends JPanel{
    public PreviewPage(){
    public void paint(Graphics g){
         super.paint(g);
         Graphics2D g2 = (Graphics2D)g;
    // PORTRAIT
         if(PF.getOrientation() == PF.PORTRAIT){
         g.setColor(Color.black);
         g.drawRect(60, 10, 340, 440);
         int x1 = (int)Math.rint( ( (double)PF.getImageableX() / 72 ) * 40 );
         int y1 = (int)Math.rint( ( (double)PF.getImageableY() / 72 ) * 40 );
         int l1 = (int)Math.rint( ( (double)PF.getImageableWidth() / 72 ) * 40 );
         int h1 = (int)Math.rint( ( (double)PF.getImageableHeight() / 72 ) * 40 );
         g.setColor(Color.red);
         g.drawRect(x1+60, y1+10, l1, h1);
         setScales();
         int x2 = (int)Math.rint( 1028 / XSC );
         int y2 = (int)Math.rint( 768 / YSC );
         Image image = new BufferedImage( x2, y2, BufferedImage.TYPE_INT_ARGB);
         PC.paint( image.getGraphics() );
         g.drawImage(image, x1+60, y1+10, l1, h1, this);
    // LANDSCAPE
         if(PF.getOrientation() == PF.LANDSCAPE){
         g.setColor(Color.black);
         g.drawRect(10, 60, 440, 340);
         int x1 = (int)Math.rint( ( (double)PF.getImageableX() / 72 ) * 40 );
         int y1 = (int)Math.rint( ( (double)PF.getImageableY() / 72 ) * 40 );
         int l1 = (int)Math.rint( ( (double)PF.getImageableWidth() / 72 ) * 40 );
         int h1 = (int)Math.rint( ( (double)PF.getImageableHeight() / 72 ) * 40 );
         g.setColor(Color.red);
         g.drawRect(x1+10, y1+60, l1, h1);
         setScales();
         int x2 = (int)Math.rint( 1028 / XSC );
         int y2 = (int)Math.rint( 768 / YSC );
         Image image = new BufferedImage( x2, y2, BufferedImage.TYPE_INT_ARGB);
         PC.paint( image.getGraphics() );
         g.drawImage(image, x1+10, y1+60, l1, h1, this);
    public void actionPerformed(ActionEvent e){
    // fit to page
         if(e.getSource() == ftp){
    // preview
         if(e.getSource() == preview){
         setProperties();
    // print
         if(e.getSource() == print){
         doPrint();
    public void setProperties(){
         if(pf1.isSelected() == true){
         PF.setOrientation(PF.PORTRAIT);
         if(pf2.isSelected() == true){
         PF.setOrientation(PF.LANDSCAPE);
         setScales();
         pp.repaint();
    public void setScales(){
         try{
         XSC = Double.parseDouble( xs.getText() );
         } catch (NumberFormatException e) { }
         try{
         YSC = Double.parseDouble( ys.getText() );
         } catch (NumberFormatException e) { }
    public void doPrint(){
         PrintThis();
    public void PrintThis(){
         PrinterJob printerJob = PrinterJob.getPrinterJob();
         Book book = new Book();
         book.append( new PrintPage(), PF );
         printerJob.setPageable(book);
         boolean doPrint = printerJob.printDialog();
         if (doPrint) {
         try {
         printerJob.print();
         } catch (PrinterException exception) {
         System.err.println("Printing error: " + exception);
    public class PrintPage implements Printable{
    public int print(Graphics g, PageFormat format, int pageIndex) {
         Graphics2D g2D = (Graphics2D) g;
         g2D.translate(format.getImageableX (), format.getImageableY ());
         disableDoubleBuffering(mp);
         System.out.println("get i x " + format.getImageableX ());
         System.out.println("get i x " + format.getImageableY ());
         System.out.println("getx: " + format.getImageableWidth() );
         System.out.println("getx: " + format.getImageableHeight() );
         // scale to fill the page
         double dw = format.getImageableWidth();
         double dh = format.getImageableHeight();
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         setScales();
         double xScale = dw / (1028/XSC);
         double yScale = dh / (768/YSC);
         double scale = Math.min(xScale,yScale);
         System.out.println("" + scale);
         g2D.scale( xScale, yScale);
         ((JPanel)PC).paint(g);
         enableDoubleBuffering(mp);
         return Printable.PAGE_EXISTS;
    public void disableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(false);
    public void enableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(true);
         Component PC;
         PageFormat PF = new PageFormat();
         double XSC = 1;
         double YSC = 1;
    // gui comp
         JPanel mp = new JPanel();
         JPanel hold = new JPanel();
         JPanel pp = new PreviewPage();
         ButtonGroup pf = new ButtonGroup();
         JRadioButton pf1;
         JRadioButton pf2;
         JLabel xsl = new JLabel("X Scale:", JLabel.LEFT);
         JTextField xs = new JTextField("1");
         JLabel ysl = new JLabel("Y Scale:", JLabel.LEFT);
         JTextField ys = new JTextField("1");
         JButton ftp = new JButton("Fit to Page");
         JCheckBox cp = new JCheckBox("Constrain Proportions");
         JButton preview = new JButton("PREVIEW");
         JButton print = new JButton("PRINT");
    }

  • Include a web browser in a multi frame application

    I am trying to include a web browser in my java app. i.e. embed one in a JInternalFrame. or JFrame.
    Is this possible. could i use like a JBrowser or something.
    Thanks
    Kind Regards
    michael

    Hi,
    I tried using the same in my Lotus notes add-in, but received the following exception -
    java.lang.IllegalStateException: The version of SWT that is required is 3.7M5 or later!
    at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface.initialize_(SWTNativeInterface.java:208)
    at chrriis.dj.nativeswing.swtimpl.NativeInterface.initialize(NativeInterface.java:71)
    at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface.open_(SWTNativeInterface.java:315)
    at chrriis.dj.nativeswing.swtimpl.NativeInterface.open(NativeInterface.java:100)
    at test.SimpleWebBrowserExample.test(SimpleWebBrowserExample.java:56)
    at desktopapplication2.lotusconnector.start(lotusconnector.java:18)
    at desktopapplication2.JavaAgent.NotesMain(JavaAgent.java:16)
    at lotus.domino.AgentBase.runNotes(Unknown Source)
    at lotus.domino.NotesThread.run(Unknown Source)
    Even though swt-3.7M5-win32-win32-x86.jar(alongwith DJNativeSwing.jar and DJNativeSwing-SWT.jar) has already been imported in the library.
    The code in which I used it -
        JPanel webBrowserPanel = new JPanel(new BorderLayout());
        webBrowserPanel.setBorder(BorderFactory.createTitledBorder("Native Web Browser component"));
        final JWebBrowser webBrowser = new JWebBrowser();
        webBrowser.navigate(<some web url to browse to>);
        //webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
        //add(webBrowserPanel, BorderLayout.CENTER);
        webBrowser.setMenuBarVisible(false);
        webBrowser.setLocationBarVisible(false);
        webBrowser.setBarsVisible(false);Regards
    Nitin

Maybe you are looking for

  • I have a big Manufacturing problem with my i phone 5  what to do now?

    Dear sir , I want to Complain for my new i phone 5 that I get it on last December its only work for three month only with out any bad using my monitor is freezed and i cant use the phone when i sent to the dealer they inform me thet mobile have a man

  • How to turn on/enable sql logging

    Our environment is Java EE 5, JPA, Weblogic 10, KODO 4.1.2, and our DB is Oracle 10gr2. We are trying to figure out what to do/what has to be set up in order to see the actual SQL going to the database. I have the following in the persistence.xml: <p

  • Specific value in one field determines value in fields

    I am building a form using Adobe Pro and I am fairly new to Java Script. One of the fields I am creating can only be a specific value (nra).  If nra is selected it needs to blank out a second field and put a number 1 in a third field. Can java script

  • OWB mapping deployment error

    Hi I got similar kind of error.. created a simple mapping for one small table.. the generated PL/SQL is as bellow. When I try to deploy the mapping I am getting warnings as shown bellow.. Could any body help me ? Warnings: ORA-06550: line 0, column 0

  • WLC 4400 question

    Hi The scenario is as follows: We deployed a WLAN with a WLC 4400 and several LWAPs. The main configuration include 2 SSID, one for guest access (internet and a limited access to internal resources) and one with complete access to the internal resour