Unicode line-drawing characters - possible Java bug?

Hi all, I am trying to draw a box using line drawing characters in UTF-8. I make the UTF-8 box file in Microsoft Word where it looks aligned. However, when I run my Java program to display the box in a JTextArea, it is all out of alignment like below. Is this a bug in Java that prevents it from displaying aligned line-drawing characters? I am tearing my hair out over this so your help is much appreciated.
Regards,
Rianmal.
╔═══════════════════╗
║║║║║║║║║║║║║║║║║║║║║
║ ║
║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║
║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║
║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║
║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║
║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║
║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║
║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║
║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║
╚═══════════════════╝

sabre,
Looks like monospaced isn't found on windows (vista)... So I used "Courier New" instead.
Sabre20090412a.java is saved with encoding=UTF-8 (i.e. CP1252) instead of the default ASCII, which doesn't support the extended characters.
package forums;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class Sabre20090412a
  private static final String text;
  static {
    String t;
    t =  "╔═══════════════════╗\n"; // LINE 12
    t += "║║║║║║║║║║║║║║║║║║║║║\n";
    t += "║                   ║\n";
    t += "║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║\n";
    t += "║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║\n";
    t += "║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║\n";
    t += "║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║\n";
    t += "║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║\n";
    t += "║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║\n";
    t += "║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║\n";
    t += "║∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙║\n";
    t += "╚═══════════════════╝\n"; // LINE 23
    text = t;
  public static void createAndShowGUI() {
    final JFrame frame = new JFrame("Test");
    final JTextArea ta = new JTextArea();
    ta.setFont(new Font("Courier New", Font.PLAIN, 14)); // <<<<< Note font-name="Courier New"
    ta.setText(text);
    frame.setContentPane(ta);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        createAndShowGUI();
build (NOTE the -encoding utf-8)*
cd /d C:\Java\home\src\forums
"C:\Program Files\Java\jdk1.6.0_12\bin\javac.exe" -encoding utf-8 -Xlint -d C:\Java\home\classes -cp c:\java\home\src;.;C:\Java\home\classes C:\Java\home\src\forums\Sabre20090412a.java
run
cd /d C:\Java\home\src\forums
"C:\Program Files\Java\jdk1.6.0_12\bin\java.exe" -cp C:\Java\home\classes forums.Sabre20090412a
References:
http://www.google.com/search?q=warning%3A+unmappable+character+for+encoding+Cp1252&hl=en
http://en.wikipedia.org/wiki/Windows-1252 #says 1252== IANIA UTF-8 except
http://www.utf8-chartable.de/unicode-utf8-table.pl #page for 2500 onwards
http://forums.sun.com/thread.jspa?threadID=5185338 #-encoding
http://www.java2s.com/Code/Java/2D-Graphics-GUI/Listallavailablefontsproviedinthesystem.htm
Roedy Green rocks!
http://mindprod.com/jgloss/font.html#AVAILABLEJ
http://mindprod.com/applet/fontshower.html
Thanx for the fish!
Cheers. Keith.

Similar Messages

  • [SOLVED] terminals & line drawing characters problem

    I use quite some escape sequences in my bash prompt, amongst them a few that produce line drawing characters. Works fine in the virtual consoles (tty), but no terminals in X (tried xterm, terminal, urxvt) display them correctly, for some reason. My locale settings seem fine, and I've tried various fonts (including the one I use in the virtual consoles).
    What could the issue be?
    FYI, my bash prompt variable. Does it display correctly for you?
    DRED='\e[0;31m'
    DGREEN='\e[0;32m'
    DYELLOW='\e[0;33m'
    DBLUE='\e[0;34m'
    DPURPLE='\e[0;35m'
    DCYAN='\e[0;36m'
    DWHITE='\e[0;37m'
    LRED='\e[1;31m'
    LGREEN='\e[1;32m'
    LYELLOW='\e[1;33m'
    LBLUE='\e[1;34m'
    LPURPLE='\e[1;35m'
    LCYAN='\e[1;36m'
    LWHITE='\e[1;37m'
    COLRESET='\e[0m'
    PS1="\n\[$DBLUE\]\[\016\]l\[\017\]\[$DRED\](\u@\h)\[$DBLUE\]\[\016\]qqq\[\017\](\[$LBLUE\]H\!\[$DBLUE\])\[\016\]qq\[\017\](\[$LBLUE\]C\#\[$DBLUE\])\[\016\]qq\[\017\](\[$LBLUE\]J\j\[$DBLUE\])\[\016\]qqq\[\017\](\[$LBLUE\]\D{%H:%M %A %d - %B %Y}\[$DBLUE\])\n\[\016\]t\[\017\]\[\016\]q\[\017\](\[\[$LBLUE\]\w\[$DBLUE\])\n\[\016\]mqq\[\017\]> \[$LBLUE\]"
    Last edited by Mzg (2010-07-09 10:00:41)

    After some detective work I have managed to come up with an explanation as well as what seems to be a working solution.
    If you have not tried the prompt above, basically I tried to use some line drawing characters in my bash prompt, but these refused to display correctly under any X terminals I tried (though it looked fine on virtual consoles).
    The problem was in the
    \[\016\] ... \[\017\]
    sequences. The \016 escape sequence is supposed to enter the alternate character set mode (common way to draw e.g. lines in text mode) while \017 returns the terminal to the standard character set. These work fine on the virtual consoles, but are apparently a no-no in (some) X terminals. If you tried the prompt you would notice that the color escape sequences worked fine, only the line drawing characters failed.
    So that is the explanation part. So for the solution...
    For urxvt, which is my preferred terminal emulator, the solution is quite simple. This should also work with other rxvt-derived terminals (including the popular aterm), though I have not tested this.
    These terminals offer the same functionality as the virtual consoles, though the escape sequences are different. "\033(0" enters alternate charset mode while "\033(B" returns to standard charset mode. So the solution is simply to replace all previous
    \[\016\] ... \[\017\]
    sequences with
    \[\033(0\] ... \[\033(B\]
    But this poses a problem, as the virtual consoles do not recognize these sequences and you'll get the same problem as before, only in text mode instead of X. I solved this by using the PROMPT_COMMAND variable to run fgconsole every time a command is ran in bash, checking if the command is ran in tty7 (i.e. X11) or in one of the (other) virtual consoles. This is my code for the root prompt:
    DRED='\e[0;31m'
    DGREEN='\e[0;32m'
    DYELLOW='\e[0;33m'
    DBLUE='\e[0;34m'
    DPURPLE='\e[0;35m'
    DCYAN='\e[0;36m'
    DWHITE='\e[0;37m'
    LRED='\e[1;31m'
    LGREEN='\e[1;32m'
    LYELLOW='\e[1;33m'
    LBLUE='\e[1;34m'
    LPURPLE='\e[1;35m'
    LCYAN='\e[1;36m'
    LWHITE='\e[1;37m'
    COLRESET='\e[0m'
    function prompt_func
    # Running in tty7 or larger (X11)
    if [ `sudo fgconsole` -gt 6 ]
    then
    PS1="\n\[$DBLUE\]\[\033(0\]l\[\033(B\]\[$DRED\](\u@\h)\[$DBLUE\]\[\033(0\]qqq\[\033(B\](\[$LBLUE\]H\!\[$DBLUE\])\[\033(0\]qq\[\033(B\](\[$LBLUE\]C\#\[$DBLUE\])\[\033(0\]qq\[\033(B\](\[$LBLUE\]J\j\[$DBLUE\])\[\033(0\]qqq\[\033(B\](\[$LBLUE\]\D{%H:%M %A %d - %B %Y}\[$DBLUE\])\n\[\033(0\]t\[\033(B\]\[\033(0\]q\[\033(B\](\[\[$LBLUE\]\w\[$DBLUE\])\n\[\033(0\]mqq\[\033(B\]> \[$LBLUE\]"
    else
    PS1="\n\[$DBLUE\]\[\016\]l\[\017\]\[$DRED\](\u@\h)\[$DBLUE\]\[\016\]qqq\[\017\](\[$LBLUE\]H\!\[$DBLUE\])\[\016\]qq\[\017\](\[$LBLUE\]C\#\[$DBLUE\])\[\016\]qq\[\017\](\[$LBLUE\]J\j\[$DBLUE\])\[\016\]qqq\[\017\](\[$LBLUE\]\D{%H:%M %A %d - %B %Y}\[$DBLUE\])\n\[\016\]t\[\017\]\[\016\]q\[\017\](\[\[$LBLUE\]\w\[$DBLUE\])\n\[\016\]mqq\[\017\]> \[$LBLUE\]"
    fi
    PROMPT_COMMAND=prompt_func
    Note that I do not claim to be a good bash programmer, so there might be better ways. This has however worked flawlessly so far, including when su'ing to other users, and switching between tty's and X.
    The code is the same for my other users, except from the colors. Note the
    `sudo fgconsole`
    Sudo proved necessary for non-root users. I added an entry in the sudoers config file to let all users run fgconsole as root without providing a password.
    Okay, that's it. It's a bit dirty, but it solved my problem at least.
    Last edited by Mzg (2010-07-10 07:06:44)

  • SQL Query problems with Mysql - possible Java bug

    I have a query that works fine on mysql, but does not work in my jsp page.... my db connection and all that jazz is fine.
    select somefields from table order by (integerfield / doublefield)
    two notes... the query works without the order by. And the query works with the order by when I'm working directly with the db. Any ideas? This is driving me nuts!!!!
    Thanks,
    Tyson

    Nevermind, just a dumb mistake... finally figured it out.

  • Muttng and putty drawing characters

    So, this has been bugging me for a time and I can't ever figure out the exact reason this happens.
    When I use putty to connect to a remote server (with TERM set to xterm-256color) and load up muttng, I get drawing characters that look like this
    Note the 'x's should be vertical lines and the 'mq' should be horizontal lines... but nope.
    I've tried messing with the fonts to no avail. Putty is set to UTF-8 mode with unicode line drawing chars, and my locale is UTF-8 enabled.
    This does *not* happen to be a problem with 'mc' (which uses slang for drawing) however, so I don't think it's a drawing issue in general. I expect it's ncurses only...
    Any ideas?

    Hmmm interestingly enough, this seems to be caused by setting putty to utf-8 mode. If I switch putty back to latin1, I get appropriate drawing characters.
    Anyone know why that is?

  • Printing unicode characters in Java - help

    Hi there,
    I want to print out unicode characters through java programming language in windows system. For example, I want to print Devanagari characters. I found out that '\u0900' to '\u0975' represent devanagari characters. So I tried following,
    out = new PrintStream(System.out, true, "UTF-8");
    out.println('\u0911');
    but they print characters like ��� and not the actual devanagari characters. Just to be more clear, devanagari script is used by Hindi, Nepali and similar languages.
    If you knew about it and could give any suggestions, that would be very helpful.
    Thanks in advance!

    priyankabhar wrote:
    I am not sure, it is just a windows system and I am trying to print to the command line. Please suggest me how I can find out if my console supports it.Use the CHCP command to find out what code page your console uses. And as already suggested, Google is a good resource if you don't know what a "code page" is.

  • Curious font name..., 'Reveal Line Draw'?

    Hello there.
    I just wrote a GUI program which displays fonts and some rendered images for styles.
    And I got a font named 'Reveal Line Draw'.
    What is it? Is it just an instance of valid font?
    Maybe my question can be 'Revealed' as one as some stupid... :)
    Here comes my source code.
    Please try to compile it and run it.
    And, maybe, you can find that thing.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Font;
    import java.awt.GraphicsEnvironment;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    import javax.swing.JRootPane;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableModel;
    public class FontViewer {
        public static void main(String[] args) {
            final String[] fontFamilyNames = GraphicsEnvironment.
                                             getLocalGraphicsEnvironment().
                                             getAvailableFontFamilyNames();
            final String[] columnNames =
                {"NAME", "PLAIN", "BOLD", "ITALIC", "BOLD ITALIC"};
            new JFrame("Font Viewer") {
                @Override
                protected JRootPane createRootPane() {
                    return new JRootPane() {
                        @Override
                        protected Container createContentPane() {
                            return new JScrollPane(new JTable() {
                                protected TableModel createDefaultDataModel() {
                                    return new AbstractTableModel() {
                                        @Override
                                        public Class getColumnClass(
                                            int columnIndex) {
                                            return Font.class;
                                        @Override
                                        public String getColumnName(int column) {
                                            return columnNames[column];
                                        public int getColumnCount() {
                                            return columnNames.length;
                                        public int getRowCount() {
                                            return fontFamilyNames.length;
                                        public Object getValueAt(int rowIndex,
                                            int columnIndex) {
                                            return null;
                                @Override
                                protected void createDefaultRenderers() {
                                    super.createDefaultRenderers();
                                    defaultRenderersByColumnClass.put(
                                        Font.class, new DefaultTableCellRenderer() {
                                        @Override
                                        public Component
                                            getTableCellRendererComponent(
                                                JTable table, Object value,
                                                boolean isSelected,
                                                boolean hasFocus, int row,
                                                int column) {
                                            Font font =
                                                Font.decode(fontFamilyNames[row]);
                                            Component renderer =
                                                super.getTableCellRendererComponent(
                                                    table, font.getName(),
                                                    isSelected, hasFocus, row,
                                                    column);
                                            if (column == 1) {
                                                renderer.setFont(font.deriveFont(
                                                    Font.PLAIN));
                                            } else if (column == 2) {
                                                renderer.setFont(font.deriveFont(
                                                    Font.BOLD));
                                            } else if (column == 3) {
                                                renderer.setFont(font.deriveFont(
                                                    Font.ITALIC));
                                            } else if (column == 4) {
                                                renderer.setFont(font.deriveFont(
                                                    Font.BOLD|Font.ITALIC));
                                            return renderer;
                @Override
                protected void processWindowEvent(WindowEvent we) {
                    super.processWindowEvent(we);
                    if (we.getID() == WindowEvent.WINDOW_CLOSING) {
                        System.exit(0);
                @Override
                public void frameInit() {
                    super.frameInit();
                    setSize(600, 400);
            }.setVisible(true);
    }

    Here are my printed font names. And I just wanna know what the bolded font works for?
    Acutally it doesn't show any renderred image on my source.
    WindowsXP SP2 JRE 1.5.0U5
    Agency FB
    Arial
    Arial Black
    Arial Narrow
    Arial Rounded MT
    Batang
    BatangChe
    Blackadder ITC
    Bodoni MT
    Bodoni MT Black
    Bodoni MT Condensed
    Book Antiqua
    Bookman Old Style
    Bookshelf Symbol
    Bradley Hand ITC
    Calisto MT
    Castellar
    Century Gothic
    Century Schoolbook
    Comic Sans MS
    Copperplate Gothic
    Copperplate Gothic Light
    Courier New
    Curlz MT
    Dialog
    DialogInput
    Dotum
    DotumChe
    Edwardian Script ITC
    Elephant
    Engravers MT
    Eras Bold ITC
    Eras Demi ITC
    Eras Light ITC
    Eras Medium ITC
    Estrangelo Edessa
    Felix Titling
    Forte
    Franklin Gothic Book
    Franklin Gothic Demi
    Franklin Gothic Demi Cond
    Franklin Gothic Heavy
    Franklin Gothic Medium
    Franklin Gothic Medium Cond
    French Script MT
    Garamond
    Gautami
    Georgia
    Gigi
    Gill Sans MT
    Gill Sans MT Condensed
    Gill Sans MT Ext Condensed
    Gill Sans Ultra
    Gill Sans Ultra Bold Condensed
    Gloucester MT Extra Condensed
    Goudy Old Style
    Goudy Stout
    Gulim
    GulimChe
    Gungsuh
    GungsuhChe
    Haettenschweiler
    Impact
    Imprint MT Shadow
    Kartika
    Latha
    Lucida Bright
    Lucida Console
    Lucida Sans
    Lucida Sans Typewriter
    Lucida Sans Unicode
    Maiandra GD
    Mangal
    Marlett
    Microsoft Sans Serif
    MingLiU
    Monospaced
    Monotype Corsiva
    MS Gothic
    MS Mincho
    MS Outlook
    MS PGothic
    MS PMincho
    MS Reference Sans Serif
    MS Reference Specialty
    MS UI Gothic
    MV Boli
    NSimSun
    OCR A Extended
    Palace Script MT
    Palatino Linotype
    Papyrus
    Perpetua
    Perpetua Titling MT
    PMingLiU
    Pristina
    Quest Font
    Raavi
    Rage
    Reveal Line Draw <<<<<<<<<<<<<<<< @@?
    Rockwell
    Rockwell Condensed
    Rockwell Extra
    SansSerif
    Script MT
    Serif
    Shruti
    SimHei
    SimSun
    Sylfaen
    Symbol
    Tahoma
    Times New Roman
    Trebuchet MS
    Tunga
    Tw Cen MT
    Tw Cen MT Condensed
    Tw Cen MT Condensed Extra
    Verdana
    Vrinda
    Webdings
    Wingdings
    Wingdings
    Wingdings
    ZWAdobeF

  • Java Bug? Centering a JLable with just an icon in a JScrollPane

    Hi,
    I'm attempting to write a image viewing program. I would like the image centered on the window displaying them, but because some images are larger than the window, I would like the image to be in the upper left hand coner of the window with scroll bars to allow you to view the rest of the image.
    I have attempted to implement this by placing a JScrollPane on a JFrame, and then placing a JLabel in the JScrollPane's Viewport. I set the Label's text to blank, and then set the image, wraped in an InageIcon, as the JLabel's Icon.
    To center the JLabel, I have tried to set the JScrollPane's Viewport's LayoutManager to two different layout managers, but I've found buggy operation with each. The Layout I've tried are the following:
    1. a GridLayout(1,1,0,0); - this works fine when the image is smaller that the available area of the JScrollPane. However, if the window is resized so that the image more than totally fills the JScrollPane, the image gets cut off. What happens is that the image is centered in the available scrollpane view, meaning the uper and left edges of the image get cut off. Scroll bars appear to let you view the lower and righer edges of the image, however, when you scroll, the newly uncovered areas of the image never get drawn, so you can't get to see the lower or right edges of the image either.
    2. a GridbagLayout with one row, and one column each with a weight of 100, centered and told to fill both horizontally and vertically. Again, this correctly centers the JLabel when th eimage is smaler than the available space in the JScrollPane. Once the window is resized so that the image is bigger than the space to view the image in, strange problems occur. This time it seems that the JScrollPane's scrollbars show that there should be enough room to show the image if the image was in the upper left corner, however, the image isn't in the upper left corner, it is offset down and to the right if the upper left corner by an amount that appears equal to the amount of extra space needed to display the image. For example, if the image is 200x300 and the view area is 150x200, ite image is offest by 50 horizontally and 100 vertically. This results in the bottom and right edges of the image getting cut off because the scrollbars only scroll far enough to show the image if the image was placed at 0,0 and not at the offset location that it is placed at.
    You may not understand what I'm trying to say from my description, but below is code that can reproduce the problem.
    Questions. Am I doing anything wrong that is causing this problem? Is that another, better way to center the JLabel that doesn't have these problems? Is this a JAVA Bug in either the layoutmanagers, JScrollPane or JLabel when it only contains an icon and no text?
    Code:
    this is the class that creates and lays out the JFrame. It currently generates a 256x256 pixel image. By changing the imagesize variable to 512, you can get a larger image to work with which will make the bug more obvious.
    When first run the application will show what happens when using the GridLayout and described in 1. There are two commented out lines just below the GridLayout code that use a GridbagLayout as descriped in method 2. Comment out the GridLayout code when you uncomment the GridBageLayout code.
    package centertest;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.image.*;
    public class Frame1 extends JFrame {
        JPanel contentPane;
        BorderLayout borderLayout1 = new BorderLayout();
        JScrollPane jScrollPane1 = new JScrollPane();
        JLabel jLabel1 = new JLabel();
        static final int imagesize=256;
        //Construct the frame
        public Frame1() {
            enableEvents(AWTEvent.WINDOW_EVENT_MASK);
            try {
                jbInit();
            catch(Exception e) {
                e.printStackTrace();
        //Component initialization
        private void jbInit() throws Exception  {
            contentPane = (JPanel) this.getContentPane();
            contentPane.setLayout(borderLayout1);
            this.setSize(new Dimension(400, 300));
            this.setTitle("Frame Title");
            //setup label
            jLabel1.setIconTextGap(0);
            jLabel1.setHorizontalAlignment(JLabel.CENTER);
            jLabel1.setVerticalAlignment(JLabel.CENTER);
            jLabel1.setVerticalTextPosition(JLabel.BOTTOM);
            //create image and add it to the label as an icon
            int[] pixels = new int[imagesize*imagesize];
            for(int i=0;i<pixels.length;i++){
                pixels=i|(0xff<<24);
    MemoryImageSource mis = new MemoryImageSource(imagesize, imagesize,
    pixels, 0, imagesize);
    Image img = createImage(mis);
    jLabel1.setIcon(new ImageIcon(img));
    jLabel1.setText("");
    contentPane.add(jScrollPane1, BorderLayout.CENTER);
    //center image using a GridLayout
    jScrollPane1.getViewport().setLayout(new GridLayout(1,1,0,0));
    jScrollPane1.getViewport().add(jLabel1);
    //Center the image using a GridBagLayout
    /*jScrollPane1.getViewport().setLayout(new GridBagLayout());
    jScrollPane1.getViewport().add(jLabel1,
    new GridBagConstraints(0, 0, 1, 1, 100.0, 100.0,
    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    new Insets(0, 0, 0, 0), 0, 0));
    //Overridden so we can exit when window is closed
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    and here is an application with which to launch the frame
    package centertest;
    import javax.swing.UIManager;
    import java.awt.*;
    public class Application1 {
        boolean packFrame = false;
        //Construct the application
        public Application1() {
            Frame1 frame = new Frame1();
            //Validate frames that have preset sizes
            //Pack frames that have useful preferred size info, e.g. from their layout
            if (packFrame) {
                frame.pack();
            else {
                frame.validate();
            //Center the window
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension frameSize = frame.getSize();
            if (frameSize.height > screenSize.height) {
                frameSize.height = screenSize.height;
            if (frameSize.width > screenSize.width) {
                frameSize.width = screenSize.width;
            frame.setLocation( (screenSize.width - frameSize.width) / 2,
                              (screenSize.height - frameSize.height) / 2);
            frame.setVisible(true);
        //Main method
        public static void main(String[] args) {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            catch (Exception e) {
                e.printStackTrace();
            new Application1();
    }I'm running Java 1.4.1 build 21 on Windows 98. I used JBuilder8 Personal to write this code.

    Hmmm,
    You are correct. Not setting a layout for the scrollpane's viewport (using the default of javax.swing.ViewportLayout) results in the positioning of the image tat I want (center the image if image is smaller than the scrollpane, if the image is larger, place it in the upper-left corener and enable the scrollbars to scroll to see the rest of the image).
    Anyone have any idea why the GridLayout and GridBagLayout act as they do? I gues it isn't that important tomy program, but I'm still not sure that they are operating correctly. (Specifically, GridLayout sha scrollbars, but when you scroll, no new parts of the image are revealed.)

  • Problem with JMenus that Persist - Is this a Java bug?

    I am having a problem with JMenus that persist. By this I mean
    that my drop down menus persist on the screen even after they have
    been selected.
    I've checked the Java bug database, and the following seems
    to come closest to my problem:
    Bug ID: 4235188
    JPopupMenus and JMenus persist when their JFrame becomes visible
    State: Closed, not a bug
    http://developer.java.sun.com/developer/bugParade/bugs/4235188.html
    This page says that the matter is closed and is not a bug. The
    resolution of this matter printed at the bottom of the page
    is completely abstruse to me and I would appreciate any
    comments to understand what they are talking about.
    The code at the end of my message illustrates my problem.
    1. Why should paintComponent() make any difference to
    Menu behavior?
    2. Is this a bug?
    3. What's the workaround if I have to paint() or repaint()?
    Thanks
    Tony Lin
    // Example of Menu Persistence Problem
    // Try running this with line 41, paintComponent(), and without line 41
    // Menus behave normally if line 41 is commented out
    // If line 41 exists, menus will persist after they have been selected
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class P2 extends JPanel {
    JMenuItem[] mi;
    public P2() {
    JFrame thisFrame = new JFrame();
    thisFrame.getContentPane().add(this);
    JMenu menu = new JMenu("My Menu");
    JMenuBar mb = new JMenuBar();
    mi = new JMenuItem[4];
    for (int i=0; i<mi.length; i++) {
    mi[i] = new JMenuItem("Menu Item " + String.valueOf(i));
    menu.add(mi);
    mb.add(menu);
    thisFrame.setJMenuBar(mb);
    thisFrame.setSize(400,200);
    thisFrame.setLocation(150,200);
    thisFrame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    System.exit(0);
    thisFrame.setVisible(true);
    public void paintComponent(Graphics g) {} //Affects menu behavior!
    public static void main(String[] args) {
    new P2();

    Well, my understanding of the way painting works is that a component doesn't UNPAINT itself. Instead a message is sent to the component under the coordinates of the menu to REPAINT itself.
    In your demo program the JFrame is the component under the JMenu. The paintComponent() method of JFrame is empty, so nothing gets repainted.
    I added super.paintComponent(g); to the method and everything works fine.

  • How to get the unicode escapes for characters outside a characterset

    Hi!
    I'm tryiing to edit into a RTF file and have been fairly successful so far. But living outside the U.S i need some characters outside ASCII. Those characters are supposed to be escaped as unicode-escapes, eg \u45. But I can't find a way to get the escapesequense for the unicode-characters that lives outside ASCII.
    I'm guessing that this is a very simple thing to do but I have not been lucky with google so far.
    So, how do I get the unicode escapes for characters outside a characterset?
    Thanks in advance
    Roland Carlsson

    I'm tryiing to edit into a RTF file and have been
    fairly successful so far. But living outside the U.S
    i need some characters outside ASCII. Those
    characters are supposed to be escaped as
    unicode-escapes, eg \u45. But I can't find a way to
    get the escapesequense for the unicode-characters
    that lives outside ASCII.You are asking about RTF and not java correct?
    As a guess....
    Unicode is 32 bit (presumably you are not using the newest one.) Thus it requires a 32 bit representation. Thus \u45 actually is the same as \u0045. Thus something like \u1e45 would probably work.

  • Junk characters in java

    Hi,
    How to block the junk characters in java when csv file uploading.
    Thanks

    Not possible. You can only do it during processing the upload at the server side. If you also don´t know how to do that, then you need to be more specific about the problem before I could give an extended answer. For instance, you should elaborate "junk" here. At least, are you familiar with character encodings and the sense of it?

  • Simple line drawing project in swing

    hi folks,
    i want to write a simple line drawing project. it has a JPanel, a JFrame and JButton.
    JPanel and JButton are on JFrame. When Button is clicked,
    a line will be added to JPanel but previous lines which have been added are not removed on JPanel.
    Could you please help me?

    i wrote below codes but it adds first line but when click button �n order to add line, it is not adding line. Please help and thanxs...
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.geom.Line2D;
    import java.util.Enumeration;
    import java.util.Vector;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.WindowConstants;
    import javax.swing.SwingUtilities;
    public class NewJFrame extends javax.swing.JFrame implements ActionListener {
         private JButton addButton;
         MainPanel mainPane ;
         public Vector lines ;
         * Auto-generated main method to display this JFrame
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        NewJFrame inst = new NewJFrame();
                        inst.getContentPane().add(new MainPanel(inst.lines));
                        inst.setLocationRelativeTo(null);
                        inst.setVisible(true);
         public NewJFrame() {
              super();
              initGUI();
              lines = new Vector();
              lines.add(0, 30);
              addButton.addActionListener(this);
         private void initGUI() {
              try {
                   setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                        addButton = new JButton();
                        getContentPane().add(addButton, BorderLayout.SOUTH);
                        addButton.setText("ADD");
                        addButton.setPreferredSize(new java.awt.Dimension(71, 21));
                   pack();
                   setSize(400, 300);
              } catch (Exception e) {
                   e.printStackTrace();
         @Override
         public void actionPerformed(ActionEvent e) {
              if(e.getSource() == addButton){
                   lines.addElement(Integer.parseInt(lines.get(0).toString())+30);
                   mainPane.repaint();
    class MainPanel extends JComponent {
         Vector tempLines ;
         MainPanel(Vector lines){
              tempLines = lines;
              setBackground(Color.white);
         public void paintComponent(Graphics g) {
              Enumeration enumeration = tempLines.elements();
              while(enumeration.hasMoreElements()) {
                   Integer point = Integer.parseInt(enumeration.nextElement().toString());
                   Line2D line = new Line2D.Double(30, point, 200, point);
         Graphics2D g2d = (Graphics2D)g;
         g2d.setStroke(new BasicStroke(5));
         g2d.draw(line);
    }

  • Canvas drawing combined arc s bug?

    Hello,
    I'm working on a HTML5 canvas game, where some areas should be drawn connceted in some kind of "blob" of circles.
    The code im using to draw looks like this, and an example can be found on github:
    https://github.com/jrie/Connect
    The error is visible when a fleet is navigated outside the main circle, to archive that:
    Click on fleet icon, click on planet, pressing T to make a turn and see the fleet moves
    At some point, some strange graphic error, looking like a triangle or extension occurs.
    Please try different distances, destionations as possible, its always producing this strange effect.
    The code in question producing the result is:
    Line 2340 until 2348
    gameScreen.beginPath();
    for (area in env.scanAreas) {
    scanArea = env.scanAreas[area];
    scanX = scanArea[1] + env.offsetX;
    scanY = scanArea[2] + env.offsetY;
    gameScreen.arc(scanX, scanY, scanArea[0], 0, 6.28);
    gameScreen.closePath();
    gameScreen.fill();
    If the beginPath and closePath and fill are all stuffed into the for loop, it draws well, but its a different effect and not one "blob" as requested in this case.

    Hello Patrick,
    thanks for coming back to me. For some reason I did find my problem, it was not really related to the order of the code, but that drawing one circle, then drawing another circle further away, without using a "canvasObject.moveTo" - there is another line draw as the "pencil" moves to the location of the new circle, creating some kind of intersection.
    I thought first that this was some kind rendering but, but now it does make some sense - thinking of a turtle drawing engine.
    Anyhow, thank you for answering!

  • I have a line drawing (black on white paper) i have scanned and need to make the white paper transparent, maintaining the line drawing, can i and then HOW can i do this in PS?

    i have a line drawing (black on white paper) i have scanned and need to make the white paper transparent, maintaining the line drawing, can i and then HOW can i do this in PS? this is for my business logo. ive used it for years but with a solid background. id like to have it just be the drawing over my photos with a transparent background.

    First let me apologize for posting a reply that was only suitable for advanced users.  Photoshop is broad and powerful therefore has a huge learning curve.  In fact I would state no one knows and uses all of Photoshop.  When we first get Photoshop it intimidate us and we're very uncomfortable using it.  Many thing are not intuitive there in much learning involved.  After some time we begin to know something and we are able to do some thing.  Learning become rapid and we start playing in Photoshop.  It is very important to play with Photoshop.  Playing with Photoshop and asking for help with in forums like this IMO is the best way to learn. 
    Photoshop Power lies in layers, selection and automation.  However it takes knowledge to use photoshop well so most powerful tool you have ins Photoshop is the gray matter between your ears.  Most at one time or another want to watermark or put a logo on their image.  So its best to automate this process. All run into a problem in the process. "Size"  We find our assets vary in size and aspect ratios. Landscape, Portraits, Panoramas and others. This complicates automation.  Vector graphics works best when size vary greatly.  If you can not work out how to create a vector solution like a custom shape.  Create your Logo and watermark large thing scale down better the up. Text scale well for text uses vectors graphics however if you rasterize text it will not scale well.
    I do not type or do English well so let me do some screen captures.  I can not stress enough how important Black, White, Grays and Blending is when it come to image processing.  Become friends with Multiply, Screen, Overlay and Luminosity blending.....
    However when there is a white or black background though you can blend them you can not add a style like a drop shadow, emboss or make it invisible setting fill to 0 so only the style is visible.  When there is contrast between the logo and background it is easy to separate the two. To select the background and delet it to have the logo with a transparent background.  Many tools can be used to create the selection hee I use my action kill white.
    Vector Shape would work better for scaling However it would be best to create the logo from scratch in a vector program like illustrator but I never had the resources to justify the Creative suite. I only had Photoshop.  Recently Adobe gave me and other a year subscription to the creative suite for our participation here.  I still have not installed anything but Photoshop,  A while back I found a program that can create vector patf for black and white art work.  It will not be as good as using something like illustrator. However vector paths can be edited in Photoshop and cleaned up some. Here is the PSD it 13MB because od the gradient http://www.mouseprints.net/old/dpr/AmPm24-7.psd

  • I tried to import a PDF of a line drawing into Photoshop Elements. The thumbnail looks fine, but when imported the file is empty. This used to work in the past. What is wrong and how do I solve this?

    I tried to import a PDF of a line drawing into Photoshop Elements. The thumbnail looks fine, but when imported the file is empty. This used to work in the past. What is wrong and how do I solve this?

    Hi
    The value of the Channel Strip volume etc is not stored within the C Strip setting, as you have discovered.
    If you really wanted, you could add a Gain plug to the strip, with it set to give the correct output level with the Fader set to 0
    (Or just set the fader manually in MS)
    CCT

  • Convert a photo to a single line drawing

    It seems I've seen this in one of the photoshop tips & tricks books but did not buy the book. Any suggestions will be appreciated.

    http://www.myjanee.com/tuts/linedraw/linedraw.htm
    Also, Google for "photoshop elements line drawing" or similar.

Maybe you are looking for