JScrollPane and TitledBorder spacing

Hello,
I have an issue with using a TitledBorder on a JScrollPane. The problem is that the border is noticeably larger than the JScrollPane inside of it. The problem can be clearly seen in these two images:
What the problem looks like:     http://www.areath.com/images/ex1.jpg
What it should look like:        http://www.areath.com/images/ex2.jpgIf the title is placed on top of the border, the problem is fixed, but it just doesn't look 'right' in this context. Obviously, the title in the border is interfering with the spacing inside of the border, but I was hoping to find a simple way to work around the problem without creating a custom border.
I am using the JGoodies Looks look and feel version 1.3.1 (http://www.jgoodies.com/downloads/libraries.html)
Thanks!

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
import javax.swing.BorderFactory;
import javax.swing.border.*;
public class TestBorderClass extends JApplet {
     private class CustomTitledBorder extends TitledBorder{
          int offset = 0;
          String secondTitle = "";
          public CustomTitledBorder(Border border,
                    String title,
                    int titleJustification,
                    int titlePosition,
                    Font titleFont,
                    Color titleColor){
       super( border,"", titleJustification, titlePosition, titleFont, titleColor);
       this.titleColor = titleColor;                  
       this.offset = offset;
       this.secondTitle = title;
          public void paintBorder(Component c,
                        Graphics g,
                        int x,
                        int y,
                        int width,
                        int height){
              //super.paintBorder(c, g, x, y, width, height);              
      FontMetrics fontmetric = getFontMetrics(titleFont);
      Color color = g.getColor();     
               Color lineColor = color;
      if((border.getClass())== javax.swing.border.LineBorder.class){
      LineBorder lineb = (LineBorder) border;                
      lineColor = lineb.getLineColor();
      g.setFont(titleFont);
               int x1, y1, x2, y2;
               x1 = x + 2;
               y1 = y + 2;
               x2 = width - 4;
               y2 = height - 4;
               int half = (int)(fontmetric.getHeight()/2);
               g.setColor(lineColor);
               g.drawLine(x1, y1, 10, y1 );
               g.setColor(getTitleColor());
               g.drawString(secondTitle, 10, half);
               g.setColor(lineColor);
               g.drawLine(10 +  fontmetric.stringWidth(secondTitle),y1, x2, y1);
      g.drawLine(x2, y1, x2, y2 );
      g.drawLine(x2, y2, x1, y2 );
      g.drawLine(x1, y2, x1, y1 );
     public void init() {
          JEditorPane area = new JEditorPane("text/html", "");
          area.setEditable(false);
          area.setOpaque(false);
          area.setText("<html><font color='white'><center><b>** This is the non-opaque JEditorPane **<br><font color='#CC0000'>With HTML formatting!</font></b></center><br><br>");
          JScrollPane scroller = new JScrollPane(area,
          JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
          JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
          scroller.setOpaque(false);
          scroller.getViewport().setOpaque(false);
          scroller.setPreferredSize(new Dimension(698, 110));
          scroller.setBorder(new CustomTitledBorder(BorderFactory.createLineBorder(Color.white), "Titled Border Test", TitledBorder.LEFT, TitledBorder.TOP,
          new Font("Times New Roman", Font.BOLD, 14), Color.white));
          setContentPane(scroller);
}

Similar Messages

  • Word doc import/export and line spacing differences with Pages '09

    When I save or open a Word .doc, the default line spacing differences messes up the document formatting, the document ends up being more pages in Pages than when I open in Word:Mac.
    One work around I learned about on this forum is to set the line spacing to "exact" in Pages. This is okay, except many Word documents have subtle line spacing before or after paragraphs and/or different size fonts in the document that affects line spacing. Setting Pages line spacing to exact makes a mess of these documents.
    Why can't Apple build a proper line spacing function into Pages so it is more compatible with Word? If they are touting compatibility, they need to make a disclaimer in their advertising as only simple documents seem to work without issues.
    Is there a better work around available?
    Thanks.
    Bud

    Bud,
    It seems that there is incompatibility in the before and after spacing (Ctrl + 0 in Word for Windows adds 12 points, if I remember correctly).
    Since you mention a .doc file, it makes me think you have a Word 2003 or earlier format. I have a couple of suggestions:
    1. If you have access to Word 2007 or Word 2008 for Mac, try saving in .docx. Basically, a .docx is compliant with Office Open XML, the ECMA standard that is the basis for the document formats in Microsoft Office 2007 and Microsoft Office 2008 for Mac.
    [Note: The Office Open XML ECMA standard, or OOXML is a source of polemic since it was donated by Microsoft and competes with Open Document Format, or ODF. You can find more here:
    http://en.wikipedia.org/wiki/OfficeOpen_XML#Implementations_of_new_2008version
    and Microsoft has stated they'll support the newer standard and retrofit Office 2007. Let's hope they do the same for Office 2008 for Mac and that Apple picks up as well with an upgrade for Pages '09 or in Pages '10]
    2. If the above does not work, I would suggest reporting this to Apple. This would indicate a compatibility problem in Office Open XML compliance, which should be independent of Word itself. A way to support this claim would be to test it in another word processor that adds space before and after a paragraph and that supports OOXML, which I think would be too much I would not bother reporting it for a Word 2003 format because it is proprietary.
    Hope it helps.

  • A small problem with a JScrollPane and child windows

    Hi !
    I have created a customized JComponent inside a JScrollPane and when my application starts I create two JTextField's that I put in the JComponent and so far it all works fine to start with, but when ever the JComponent is redrawn after that the JTextField's are overdrawn or at least are not visible any longer...
    Do I need to repaint the sub components of my own JComponent myself or am I doing something very wrong here ?
    a JScrollPane
    a JComponent with some drawing going on in paint()
    a JTextField
    another JTextField
    Mikael

    Ooppps !
    Forget about it, I forgot to put a super.paint( g) at the top of my paint method, that was the problem.
    Mikael

  • How to use line wrapping and line spacing in java?how to use line wrapping

    how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?

    Hello,
    You should post your question at:
    http://java.forum.sun.com
    Thanks
    - Rose

  • How to use line wrapping and line spacing in java?

    how to use line wrapping and line spacing in java?

    Hi,
    This is explained in the java Tutorial. Please see the link:
    http://java.sun.com/docs/books/tutorial/i18n/text/line.html
    and find some sample examples.
    Hope this helps,
    --Sun/DTS                                                                                                                                                                                                                                                                                                                                                                                       

  • JTable, JScrollPane, and JinternalFrame problems.

    I have this internal frame in my application that has a scrollpane and table in it. Some how it won't let me selelct anything in the table. Also it scrolls really weird. There's a lot of chopping going on. Here's my code for the internal frame:
    public class BCDEObjectWindow extends javax.swing.JInternalFrame{
        private Vector bcdeObjects = new Vector();
        private DefaultTableModel tModel;
        public BCDEObjectWindow(JavaDrawApp p) {
            initComponents();
            this.setMaximizable(false);
            this.setClosable(false);
            this.setIconifiable(true);
            this.setDoubleBuffered(true);
            objectTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
            listScrollPane.setColumnHeaderView(new ObjectWindowHeader());
            pack();
            this.setVisible(true);
            parent = p;
            getAllBCDEFigures();
            setPopupMenu();
            tModel = (DefaultTableModel) objectTable.getModel();
            objectTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        public void getAllBCDEFigures() {
            bcdeObjects.removeAllElements();
            int i;
            for (i = 0; i < bcdeObjects.size(); i++) {
                tModel.removeRow(0);
        public void addBCDEFigure(BCDEFigure b) {
            bcdeObjects.add(b);
            tModel.addRow(new Object[]{b.BCDEName, "incomplete"});
        public void changeLabelName(BCDEFigure b) {
            if (bcdeObjects.contains(b)) {
                int index = bcdeObjects.indexOf(b);
                tModel.removeRow(index);
                tModel.insertRow(index, new Object[]{b.BCDEName, "incomplete"});
        public void removeBCDEFigure(BCDEFigure b) {
            int index = 0;
            if (bcdeObjects.contains(b)) {
                index = bcdeObjects.indexOf(b);
                bcdeObjects.remove(b);
                tModel.removeRow(index);
        public void removeAllBCDEFigures(){
            int i;
            for (i = 0; i < bcdeObjects.size(); i++) {
                tModel.removeRow(0);
            bcdeObjects.removeAllElements();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            listScrollPane = new javax.swing.JScrollPane();
            objectTable = new javax.swing.JTable();
            getContentPane().setLayout(new java.awt.FlowLayout());
            setBackground(new java.awt.Color(255, 255, 255));
            setIconifiable(true);
            setTitle("BCDE Objects");
            listScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            listScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            listScrollPane.setPreferredSize(new java.awt.Dimension(250, 150));
            objectTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                new String [] {
                    "Name", "Status"
                boolean[] canEdit = new boolean [] {
                    true, false
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit [columnIndex];
            objectTable.setColumnSelectionAllowed(true);
            listScrollPane.setViewportView(objectTable);
            jPanel1.add(listScrollPane);
            getContentPane().add(jPanel1);
            pack();
        }// </editor-fold>
        // Variables declaration - do not modify
        private javax.swing.JPanel jPanel1;
        private javax.swing.JScrollPane listScrollPane;
        private javax.swing.JTable objectTable;
        // End of variables declaration
    }and this is how i create the object in my JFrame:
    bcdeOW = new BCDEObjectWindow(this);
            bcdeOW.setLocation(400, 0);
            if (getDesktop() instanceof JDesktopPane) {
                ((JDesktopPane)getDesktop()).setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
                ((JDesktopPane)getDesktop()).add(bcdeOW, JLayeredPane.PALETTE_LAYER);
            } else
                getDesktop().add(bcdeOW);Any help would be great. Thanks a lot.

    Rajb1 wrote:
    to get the table name to appear
    create a scollpane and put the table in the scrollpane and then add the the scollpane to the component:
    //declare
    scrollpane x;
    //body code
    scrollpane x - new scrollpane();
    table y = new table();
    getContentPane().add(x(y));What language is this in, the lambda calculus -- add(x(y))!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Problem with JScrollPane and Mouse Event in JDK 1.4

    The folowing code works fine with JDK 1.3. But not with JDK 1.4. It has got a JPanel(main panel) which hosts JScrollPane which hosts another JPanel (drawing Panel). If I remove(do not add) JScrollPane to the main Panel and ad drawing panel directly to the main panel, it works.
    Thanks.
    In order to replicate the exact scenario, I have modified Sun's tutorial ScrollDemo2.java
    * This code is based on an example provided by John Vella,
    * a tutorial reader.
    import javax.swing.*;
    import javax.swing.event.MouseInputAdapter;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class ScrollDemo2 extends JPanel {
    private Dimension size; // indicates size taken up by graphics
    private Vector objects; // rectangular coordinates used to draw graphics
    private final Color colors[] = {
    Color.red, Color.blue, Color.green, Color.orange,
    Color.cyan, Color.magenta, Color.darkGray, Color.yellow};
    private final int color_n = colors.length;
    JPanel drawingArea;
    public ScrollDemo2() {
    setOpaque(true);
    size = new Dimension(0,0);
    objects = new Vector();
    //Set up the instructions.
    JLabel instructionsLeft = new JLabel(
    "Click left mouse button to place a circle.");
    JLabel instructionsRight = new JLabel(
    "Click right mouse button to clear drawing area.");
    JPanel instructionPanel = new JPanel(new GridLayout(0,1));
    instructionPanel.add(instructionsLeft);
    instructionPanel.add(instructionsRight);
    class MyScrollPane extends JScrollPane
    MyScrollPane(JPanel drawingArea)
    super(drawingArea);
    public void grabFocus()
    super.grabFocus();
    public void requestFocus()
    super.requestFocus();
    protected void processFocusEvent(FocusEvent e)
    if ( e.getID() == FocusEvent.FOCUS_GAINED )
    int i = 0;
    else
    if( e.getID() == FocusEvent.FOCUS_LOST )
    int i = 0;
    super.processFocusEvent(e);
    //Set up the drawing area.
    drawingArea = new JPanel() {
    protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Rectangle rect;
    for (int i = 0; i < objects.size(); i++) {
    rect = (Rectangle)objects.elementAt(i);
    g.setColor(colors[(i % color_n)]);
    g.fillOval(rect.x, rect.y, rect.width, rect.height);
    g.drawString("Hello",100,100);
    protected void processMouseEvent(MouseEvent pEvent)
    if(pEvent.getID() == pEvent.MOUSE_PRESSED)
    super.processMouseEvent(pEvent);
    else
    super.processMouseEvent(pEvent);
    drawingArea.setBackground(Color.LIGHT_GRAY);
    addMouseListener(new MyMouseListener());
    //Put the drawing area in a scroll pane.
    JScrollPane scroller = new MyScrollPane(drawingArea);
    scroller.setPreferredSize(new Dimension(200,200));
    setLayout(new BorderLayout());
    add(scroller, BorderLayout.CENTER);
    //If the above line is commented and the line bellow will be uncommented it works.
    //add(drawingArea, BorderLayout.CENTER);
    protected void processMouseEvent(MouseEvent pEvent)
    if(pEvent.getID() == pEvent.MOUSE_PRESSED)
    super.processMouseEvent(pEvent);
    else
    super.processMouseEvent(pEvent);
    class MyMouseListener extends MouseInputAdapter {
    final int W = 100;
    final int H = 100;
    public void mouseReleased(MouseEvent e) {
    boolean changed = false;
    if (SwingUtilities.isRightMouseButton(e)) {
    // This will clear the graphic objects.
    objects.removeAllElements();
    size.width=0;
    size.height=0;
    changed = true;
    } else {
    int x = e.getX() - W/2;
    int y = e.getY() - H/2;
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    Rectangle rect = new Rectangle(x, y, W, H);
    objects.addElement(rect);
    drawingArea.scrollRectToVisible(rect);
    int this_width = (x + W + 2);
    if (this_width > size.width)
    {size.width = this_width; changed=true;}
    int this_height = (y + H + 2);
    if (this_height > size.height)
    {size.height = this_height; changed=true;}
    if (changed) {
    //Update client's preferred size because
    //the area taken up by the graphics has
    //gotten larger or smaller (if cleared).
    drawingArea.setPreferredSize(size);
    //Let the scroll pane know to update itself
    //and its scrollbars.
    drawingArea.revalidate();
    drawingArea.repaint();
    public static void main (String args[]) {
    JFrame frame = new JFrame("ScrollDemo2");
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}
    frame.setContentPane(new ScrollDemo2());
    frame.pack();
    frame.setVisible(true);

    I tried it . It didn't work.
    Thanks for the suggestionI've got it... I know that inside the paitComponet method you can't call setSize() in jdk1.4, but you could in previous versions... that has caused al lot of problems to me...
    Abraham

  • Line and paragraph spacing in pages 5.1

    Line spacing in Pages 5.1 does not seem to be incremental any more and I cannot see how to adjust paragraph spacing at all. Any suggestions?? This is on a Mac using the

    Thanks.
    It is a layout problem that seems to be affecting most users.
    There, but overlooked.
    Hope the Apple programmers are paying attention.
    I am really curious why they seem to be doing no independent testing and checking. At least none that shows.
    Peter

  • Help With JScrollPane and many JLabels...

    I am in the process of designing an 'image browser' applet for a client, but am having some difficulty in deciding how I can most elegantly meet all of the requirements. The specification calls for an applet that can view up to 400 images (all images are small - 120 * 120 px), the view of the images can be scrolled (if not all are in the view) or scaled (zoom in and out on any area), and the images will need to 'animate' or move to new locations as sorting criteria changes. Also, I need to be able to group images into arbitrary n*n arrays and click on any image in the view (rollovers may also be necessary in the future).
    At first, I thought this would be easily solved by putting the images (JLabels?) into as many groups (JPanels?) as necessary to meet the sort criteria, then adding the groups to my main view (JScrollPane w/JPanel) in a GridLayout. My current attempt at a solution scales the groups (JPanels) via. an overridden paintComponent method from within my main scrolling view (using g2d and scale). Unfortunately, I now have many problems that I am having trouble solving:
    1. After I re-scale the JScrollPane (zoom in or out) and then try and scroll, the new images that scroll in are either garbled or just junk (seems like remnants of the original, non-scaled components?).
    2. The scrollbars, at first, were not reflecting the current scaling and how much content is visible, so I overrode the getPreferredSize method in my JScrollPane content object to return (super.getPreferredSize * scaleFactor) - this fixes the appearance of the scroll bars (ie. they accurately reflect how much content there is), but it also offsets all of the images left depending on the scale value (less scale -> images offset further left).
    3. I need pixel-perfect control over the images, so that I can animate the transition from one 'group' to another - I can't see a way to achieve this with my current solution.
    Has anyone tried to do something like this before? What is a good way of accomplishing what I need here? Any code out there that does something similar? Any help would be appreciated, I've been banging my head against the wall over this for days now...
    Thanks in advance,
    Mike P.
    Here is some relevant code:
    /* From BrowserPanel (JPanel associated with my main JScrollPane) */
    public void paint (Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.scale(scaleFactor, scaleFactor);
        super.paint(g2d);
    /* From BrowserPanel (JPanel associated with my main JScrollPane) */
    public Dimension getPreferredSize() {
        Dimension origSize = super.getPreferredSize();
        double originalSizeX;
        double originalSizeY;
        originalSizeX = origSize.getWidth();
        originalSizeY = origSize.getHeight();
        double newSizeX = originalSizeX * scaleFactor;
        double newSizeY = originalSizeY * scaleFactor;
        String strX = Double.toString(newSizeX);
        String strY = Double.toString(newSizeY);
        /* Round the string (discard anything after the decimal) */
        strX = strX.substring(0, strX.indexOf("."));
        strY = strY.substring(0, strY.indexOf("."));
        /* Convert string to int... */     
        int x = Integer.parseInt(strX);
        int y = Integer.parseInt(strY);
        return new Dimension(x, y);
    }

    I increased the frame size to 3 lines and noticed the the flickering is a result of the text area painting itself without the scrollbar and then repainting itself with the scrollbar. I don't know why this happens, but a work around is to use:
    ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,

  • 2 JScrollPanes and 1 JTable

    I have searched for about an hour and I can't find anything related to this. I apologize in advance if this is a repeat post.
    I have a JTable that is being displayed in a JScrollPane that is nestled into a JFrame. I am attempting to build another Scroll Pane with the same table in it, using the following code.:
    JScrollPane scrollPane = new JScrollPane(this.table);
    int width = this.table.getPreferredSize().width + 5;
    int height = this.table.getPreferredSize().height + 5 +
                         this.table.getTableHeader().getHeight();
    Dimension ps = new Dimension( width, height );
    scrollPane.setPreferredSize(ps);
    JWindow window = new JWindow();
    window.setSize(ps);
    window.getContentPane().add(scrollPane);
    window.pack();
    window.show();The new window displays fine and the table shows up, but the original table disappears as soon as the JFrame it is in redraws?! Can anybody provide an explanation of why this is happening and hopefully how to fix it?

    A Swing component can only belong to one container. Thanks, that was the small but very important piece of information I didn't know. I already had implemented something similar to what you suggested, but it was a little more complicated due to the nature of the table. I was hoping to get away with being lazy. Oh well...

  • JSplitPane, JScrollPane and JTree resizing

    Hi,
    In a JSplitPane, I have, in the left part, a JScrollPane, containing a JTree and, in the right part, I have an other panel.
    When I click on different nodes in the JTree, the width of the left part changes, so the JSplitPane separator moves. How to avoid that ? I would prefer a scrolling move inside the JScrollPane !
    I am using JDK 1.3
    Thanks
    Olivier Scalbert

    Try to define the JScrollPane as
    public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
    Use vsbPolicy and hsbPolicy like the VERTICAL_SCROLLBAR_AS_NEEDED
    HORIZONTAL_SCROLLBAR_AS_NEEDED respectively.
    Then define the setPreferredSize to your JScrollPane. This preferredSize must be smaller than the size of the Component view if you want to see the ScrollBar.
    By the way, when you define your JSplitPane have to define the setOneTouchExpandable(true);?

  • Positioning HorizontalBar in JScrollPane and scroller

    Hi,
    I have attached a JScrollPane to a text area.
    the code is as follows.
    JScrollPane jsp = new JScrollPane( jtx1 );
    however since the contents in the JTextArea is large horizontally, the text gets displayed in the textarea. However the scroller in the JScrollPane gets positioned towards the end of the text. How do I specify to make sure that the Scroller is always in the start of the text?
    and also i wanted the Vertical ScrollBar to be always visble and what i did was:
    int vpolicy = jsp.getVerticalScrollBarPolicy();
    jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    The Vertical ScrollBar gets displayed. However I am not ablt to see the scroller in the JScrollPane's vertical bar as I don't have sufficient text vertically. How do i specify that the scroller always be present in my vertical side...irrespective of the contents in the Textarea. i.e i always want to scroll. (I see the ScrollBAr. however am not able to scroll b'coz i have less text.)
    Thanks!
    Karthik.

    Hi,
    I have attached a JScrollPane to a text area.
    the code is as follows.
    JScrollPane jsp = new JScrollPane( jtx1 );
    however since the contents in the JTextArea is large horizontally, the text gets displayed in the textarea. However the scroller in the JScrollPane gets positioned towards the end of the text. How do I specify to make sure that the Scroller is always in the start of the text?
    and also i wanted the Vertical ScrollBar to be always visble and what i did was:
    int vpolicy = jsp.getVerticalScrollBarPolicy();
    jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    The Vertical ScrollBar gets displayed. However I am not ablt to see the scroller in the JScrollPane's vertical bar as I don't have sufficient text vertically. How do i specify that the scroller always be present in my vertical side...irrespective of the contents in the Textarea. i.e i always want to scroll. (I see the ScrollBAr. however am not able to scroll b'coz i have less text.)
    Thanks!
    Karthik.

  • Title and Caption Spacing

    How do you adjust the spacing between caption and title elements and there relative distance from the object they refer to? I need my titles to be closer to the video element. There's currently too big of a gap and i cant seem to get it close enough. I thought this is just the way it is but I looked at the Life On Earth book and the titles/captions are only about 10pts from the video.

    With line art, if there is anything extraneous in the art (even something that does not show but which you can select), the container into which the art is placed in iBook Author will be too big. Perhaps making sure there is nothing extraneous around the border of the image for the video element would fix?

  • 2 swing questions: JScrollPane and displaying pictures

    I'm building a GUI for a toy application I have written, I have two questions:
    1-The main window is inherited from JFrame, There is a JTabbedPane attached to it, and a JPanel as the first tab of the tabbed pane. There are so many jcomponents in this JPanel, this makes it too big for small resolution computers (below 1024 * 768), I would like to add this JPanel to a JScrollPane to make it behave like a text area, I've done it but it didn't work, obviously there is something I'm missing.
    2-My application calls another program to create some images at runtime which will be displayed in the other tabs, after calling the program and creating the image, I get the filename of the image. What is the best way to display this image?
    I have tried JLabel's but they don't update their pictures for some reason after it has been changed.
    Thanx in advance.

    Updated and tested code, hopefully this will help.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    public class ImagePanel extends JPanel {
      private String imageFilename = null;
      private Image image = null;
      private Toolkit toolkit = null;
      public ImagePanel() {
        super();
        toolkit = Toolkit.getDefaultToolkit();
      public void setImageFilename(String filename) {
        imageFilename = filename;
        try {
          image = toolkit.createImage(imageFilename);
          setPreferredSize(new Dimension(image.getWidth(this), image.getHeight(this)));
          repaint();
        } catch (Exception e) {
          e.printStackTrace();
          imageFilename = null;
          image = null;
      public Dimension getPreferredSize() {
           if (image == null) return new Dimension(0, 0);
           else return new Dimension(image.getWidth(this), image.getHeight(this));
      protected void paintComponent(Graphics g) {
           Insets insets = getInsets();
           g.setColor(Color.white);
           g.fillRect(0,0, insets.left + getWidth(), insets.top + getHeight());
        if (image != null) {
          g.drawImage(image, insets.top, insets.left, this);
      public void reloadImage() {
           if (imageFilename != null) {
          try {
            image = toolkit.createImage(imageFilename);
            repaint();
          } catch (Exception e) {
            imageFilename = null;
            image = null;
      public static void main(String args[]) {
           JFrame frame = new JFrame();
           frame.addWindowListener(
                new WindowAdapter() {
                     public void windowClosing(WindowEvent we) {
                          System.exit(0);     
           frame.setSize(600, 400);
           JPanel parentPanel = new JPanel();
           parentPanel.setLayout(new GridLayout(1,1));
           JTabbedPane tabPane = new JTabbedPane();
           ImagePanel imagePanel = new ImagePanel();
           JScrollPane scrollPane = new JScrollPane(imagePanel);
           imagePanel.setImageFilename("C:\\dell\\drivers\\R27748\\mrmfiles\\image015.jpg");
           parentPanel.add(scrollPane);
           tabPane.addTab("Tab 1", parentPanel);
           frame.getContentPane().add(tabPane);
           frame.show();
    }

  • How to center menu and add spacing between buttons?

    Here is my site: http://lauraportfolio.hostoi.com/index.html (If you are using Google Chrome you can right click and select "view page source" to see the html of the page)
    See how the menu button are justified the left of the light pink menu bar? How can I put them in the center?
    I would like to know how to center the menu, and then add spacing between the buttons.
    At one point I added spacing between the buttons using CSS padding, but when I did that the last menu button, "Graphics" ran off the pink menu bar and became invisible and all kinds of crazy ugly stuff!
    Below is what I beleive to be all of the CSS styling for the menu:
    #menubar
              width: 900px;
              height: 72px;
              padding: 0;
              background-color: transparent;
              background-image: url(transparentpink.png);
              background-repeat: repeat;
    ul#menu, ul#menu li
    { float: left;
      margin: 0;
      padding: 0;}
    ul#menu li
              list-style: none;
              padding-right: 0px;
              padding-left: 0px;
              margin-right: auto;
              margin-left: auto;
    ul#menu li a
              letter-spacing: 0.1em;
              display: block;
              float: left;
              height: 37px;
              text-align: center;
              color: #f0dbca;
              text-transform: none;
              text-decoration: none;
              background: transparent;
              font-family: bonvenoCF, verdana, Geneva, sans-serif;
              font-size: 150%;
              font-style: normal;
              font-weight: normal;
              font-variant: normal;
              padding-top: 29px;
              padding-right: 26px;
              padding-bottom: 6px;
              padding-left: 26px;
    ul#menu li a:hover, ul#menu li.selected a, ul#menu li.selected a:hover
              color: #F0DBCA;
              background-color: #F1836A;

    PART 1
    So as long as the width of the buttons plus the padding doesn't go over 900px it won't run off the page?
    Right.   The "box model" in CSS works like this:
    width + padding + border = actual visible/rendered width of box
    height + padding + border = actual visible/rendered height of box.
    PART 2
    And do you know how I can center the whole thin instead of it being left-aligned on the menu bar?
    You can't center floated menu items.  The best you can do is make your menu fit the entire width of the container (or as close as you can) as described in PART 1 above. 
    To center your #menu container, use margin:0 auto;
    To center text, use text-align:center on the #menu li a.
    Nancy O.

Maybe you are looking for