Text Direction

hi everyone i was wondering if there is a way to change the text direction from horizontal to vertical please reply as soon as possiblethanks in advance mike
[178 byte] By [hello.everyonea] at [2007-11-27 6:46:26]
# 1
http://www.google.com/search?hl=en&q=java+vertical+text&btnG=Google+Search
Nethera at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 2
lol i tried that didnt find anything
hello.everyonea at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 3
> lol i tried that didnt find anythingwow thats interesting, for me the 2nd link looked good
Nethera at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 4
label3.setVerticalTextPosition(label3.VERTICAL);i tried that but it didnt help
hello.everyonea at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 5
> wow thats interesting, for me the 2nd link looked good Have you looked at the OP other postings. Unless you spoon feed the answer the posting goes on for 20-30 replies as the OP continually asks for help. You gave it your best effort....
camickra at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 6
huh?
hello.everyonea at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 7
> Have you looked at the OP other postings. No, I guess I should have...and I will in the future
Nethera at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 8
i showed u the code andd it shoudl work but it aint
hello.everyonea at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 9

> i showed u the code andd it shoudl work but it aint

Well, the code you posted was:

label3.setVerticalTextPosition(label3.VERTICAL);

setVerticalTextPosition. Position. Not direction. There's a difference.

The JLabel tutorial explains what that method does

http://java.sun.com/docs/books/tutorial/uiswing/components/label.html

Torgila at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 10
any idea?
hello.everyonea at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 11
label1.setVerticalTextPosition(JLabel.BOTTOM);label1.setHorizontalTextPosition(JLabel.CENTER);it shows that which is exactly what i did
hello.everyonea at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 12
Do you ever actually pay any attention to what people say?It is not supported by an standard Swing component!!!!!!!!!!!You where given the answer in the first reply, so quit wasting everybodies time and do some reading and searching the web on your own.
camickra at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 13
i tried the first reply it compiled but it didnt change the direction
hello.everyonea at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 14
so wat would u say is wrong with the code?
hello.everyonea at 2007-7-12 18:18:57 > top of Java-index,Desktop,Core GUI APIs...
# 15
> so wat would u say is wrong with the code? What code? You haven't posted any code. We have no idea what you are talking about.
camickra at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 16
ya i did label3.setVerticalTextPosition(label3.CENTER);
hello.everyonea at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 17
See reply 12!!!!!!!!!
camickra at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 18
im still new to java so i dont no a whole lot
hello.everyonea at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 19

> im still new to java so i dont no a whole lot

Frankly, I'm tired of you stating that in every posting you make. Your knowledge is not important.

Being able to follow the advice given to you in the forum is more important. You haven't made a single effort to follow the advice you've received in this posting.

camickra at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 20
everything u told me to do i tried for a while and i gave up cuz it compiled fine but the text didnt change directions
hello.everyonea at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 21
> im still new to java so i dont no a whole lot Still no idea what you are talking about. You haven't posted the code you used.
camickra at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 22

import javax.swing.*;

import javax.swing.border.*;

import java.awt.event.*;

import java.awt.*;

import java.awt.*;

import java.applet.*;

import java.net.URL;

import java.util.*;

public class sl extends JPanel {

public static void main(String[] argv) {

JFrame frame = new JFrame();

JTabbedPane tab = new JTabbedPane();

JPanel home = new JPanel();

JPanel game = new JPanel();

JPanel events = new JPanel();

JPanel pictures = new JPanel();

frame.getContentPane().add(tab);

tab.add("Home", home);

tab.add("Game", game);

tab.add("Events", events);

tab.add("Pictures", pictures);

home.setLayout(null);

game.setLayout(null);

events.setLayout(null);

pictures.setLayout(null);

String borderStr = " 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007"+

" 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007"+

" 2006-2007 2006-2007 2006-2007 ";

JLabel text1 = new JLabel("Mr.");

game.add(text1);

text1.setSize(50,20);

text1.setLocation(20,20);

text1.setForeground(Color.blue);

JLabel text2 = new JLabel("Mr.");

game.add(text2);

text2.setSize(50,20);

text2.setLocation(20,50);

text2.setForeground(Color.black);

JLabel text3 = new JLabel("Mr.");

game.add(text3);

text3.setSize(50,20);

text3.setLocation(20,80);

text3.setForeground(Color.blue);

JLabel text4 = new JLabel("Mr.");

game.add(text4);

text4.setSize(50,20);

text4.setLocation(20,110);

text4.setForeground(Color.black);

JLabel text5 = new JLabel("Mr.");

game.add(text5);

text5.setSize(50,20);

text5.setLocation(20,140);

text5.setForeground(Color.blue);

JLabel text6 = new JLabel("Mr.");

game.add(text6);

text6.setSize(50,20);

text6.setLocation(20,170);

text6.setForeground(Color.black);

JLabel text7 = new JLabel("Mr.");

game.add(text7);

text7.setSize(50,20);

text7.setLocation(20,200);

text7.setForeground(Color.blue);

JLabel text8 = new JLabel("Mr.");

game.add(text8);

text8.setSize(50,20);

text8.setLocation(20,230);

text8.setForeground(Color.black);

JLabel text9 = new JLabel("Mr.");

game.add(text9);

text9.setSize(50,20);

text9.setLocation(20,260);

text9.setForeground(Color.blue);

JLabel text10 = new JLabel("Mr.");

game.add(text10);

text10.setSize(50,20);

text10.setLocation(20,290);

text10.setForeground(Color.black);

JLabel text11 = new JLabel("Mr.");

game.add(text11);

text11.setSize(50,20);

text11.setLocation(20,320);

text11.setForeground(Color.blue);

JLabel text12 = new JLabel("Mr.");

game.add(text12);

text12.setSize(50,20);

text12.setLocation(20,350);

text12.setForeground(Color.black);

JLabel text13 = new JLabel("Mr.");

game.add(text13);

text13.setSize(50,20);

text13.setLocation(20,380);

text13.setForeground(Color.blue);

JLabel text14 = new JLabel("Mr.");

game.add(text14);

text14.setSize(50,20);

text14.setLocation(20,410);

text14.setForeground(Color.black);

JLabel label1 = new JLabel("Stephan Lewis Secondary School");

home.add(label1);

label1.setSize(1280,125);

label1.setLocation(5,25);

label1.setFont(new Font("Jokerman", Font.BOLD, 70));

label1.setForeground(new Color(47,173,241));

JLabel label2 = new JLabel("MICAF. - COPYRIGHT 2007 - ALL RIGHTS RESERVED");

home.add(label2);

label2.setSize(370,25);

label2.setLocation(450,685);

label2.setFont(new Font("Times New Roman", Font.PLAIN, 12));

label2.setForeground(Color.red);

JLabel label3 = new JLabel("Who Am I?");

game.add(label3);

label3.setSize(400,400);

label3.setLocation(200,200);

[b]label3.setVerticalTextPosition(label3.CENTER);[/b]

TitledBorder border1 = new TitledBorder(borderStr);

home.setBorder(border1);

TitledBorder border2 = new TitledBorder(borderStr);

game.setBorder(border2);

TitledBorder border3 = new TitledBorder(borderStr);

events.setBorder(border3);

TitledBorder border4 = new TitledBorder(borderStr);

pictures.setBorder(border4);

ImageIcon cup90 = new ImageIcon("C:\\Documents and Settings\\Meaf\\My Documents\\My Pictures\\stripes123.gif");

JLabel labe1 = new JLabel(cup90);

home.add(labe1);

labe1.setSize(1280,770);

labe1.setLocation(0,70);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(1280,770);

frame.setTitle("Stephen Lewis Secondary School");

frame.setVisible(true);

}

}

Message was edited by:

hello.everyone

Message was edited by:

hello.everyone

hello.everyonea at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 23
Why did you post that code?How does that code relate to the suggestion in reply 1?Have you read reply 12 yet? What part of IT IS NOT SUPPORTED do you not understand?
camickra at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 24
the y part..i no there is a way of turing the text sideways but no one will help me b/c i tried al the things they told me
hello.everyonea at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 25
> i tried al the things they told me You haven't tried a single thing that was suggested.You where given the answer in reply 1.
camickra at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 26
are i clicked the link and tried sopem codes out ...nothign worked
hello.everyonea at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 27
> are i clicked the link and tried sopem codes out ...nothign worked If you say so I"m too tired to be bothered with you.
camickra at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 28
it seems that u already no the code i need to make it work so y dont u just tell me it and explain it
hello.everyonea at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 29
i will wait here i dont want to be ur enime i rather be ur friend..if u want to be friends that would be great we could do java together...anyways i hope u will find it in u to tell em the proper code but for now i have to go..thanks
hello.everyonea at 2007-7-21 22:05:53 > top of Java-index,Desktop,Core GUI APIs...
# 30

> so y dont u just tell me it and explain it

Because you need to learn to follow advice given on the forum, we are not going to spoon feed the answer for you.

You also need to learn to provide information so we can help you.

Saying that "it doesn't work" doesn't help us. We have no idea what link you read, or what code you used. We are not mind readers.

Once you start asking meaningfull questions and start providing meaningfull details of the problem you might start getting more help.

camickra at 2007-7-21 22:05:58 > top of Java-index,Desktop,Core GUI APIs...
# 31

hi,

try this

package com.ani;

import java.awt.Component;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.FontMetrics;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.GridLayout;

import java.beans.PropertyChangeEvent;

import java.beans.PropertyChangeListener;

import javax.swing.Icon;

import javax.swing.JComponent;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class VTextIcon implements Icon, PropertyChangeListener

{

StringfLabel;

String[]fCharStrings;

int[]fCharWidths;

int[]fPosition;

intfWidth, fHeight, fCharHeight, fDescent;

intfRotation;

ComponentfComponent;

static final intPOSITION_NORMAL= 0;

static final intPOSITION_TOP_RIGHT= 1;

static final intPOSITION_FAR_TOP_RIGHT= 2;

public static final intROTATE_DEFAULT= 0x00;

public static final intROTATE_NONE= 0x01;

public static final intROTATE_LEFT= 0x02;

public static final intROTATE_RIGHT= 0x04;

public VTextIcon(Component component, String label)

{

this(component, label, ROTATE_DEFAULT);

}

public VTextIcon(Component component, String label, int rotateHint)

{

fComponent = component;

fLabel = label;

fRotation = verifyRotation(label, rotateHint);

calcDimensions();

fComponent.addPropertyChangeListener(this);

}

public void setLabel(String label)

{

fLabel = label;

fRotation = verifyRotation(label, fRotation);

recalcDimensions();

}

public void propertyChange(PropertyChangeEvent e)

{

String prop = e.getPropertyName();

if ("font".equals(prop))

{

recalcDimensions();

}

}

void recalcDimensions()

{

int wOld = getIconWidth();

int hOld = getIconHeight();

calcDimensions();

if (wOld != getIconWidth() || hOld != getIconHeight())

fComponent.invalidate();

}

void calcDimensions()

{

FontMetrics fm = fComponent.getFontMetrics(fComponent.getFont());

fCharHeight = fm.getAscent() + fm.getDescent();

fDescent = fm.getDescent();

if (fRotation == ROTATE_NONE)

{

int len = fLabel.length();

char data[] = new char[len];

fLabel.getChars(0, len, data, 0);

fWidth = 0;

fCharStrings = new String[len];

fCharWidths = new int[len];

fPosition = new int[len];

char ch;

for (int i = 0; i < len; i++)

{

ch = data[i];

fCharWidths[i] = fm.charWidth(ch);

if (fCharWidths[i] > fWidth)

fWidth = fCharWidths[i];

fCharStrings[i] = new String(data, i, 1);

if (sDrawsInTopRight.indexOf(ch) >= 0)

fPosition[i] = POSITION_TOP_RIGHT;

else if (sDrawsInFarTopRight.indexOf(ch) >= 0)

fPosition[i] = POSITION_FAR_TOP_RIGHT;

else

fPosition[i] = POSITION_NORMAL;

}

fHeight = fCharHeight * len + fDescent;

}

else

{

fWidth = fCharHeight;

fHeight = fm.stringWidth(fLabel) + 2 * kBufferSpace;

}

}

public void paintIcon(Component c, Graphics g, int x, int y)

{

g.setColor(c.getForeground());

g.setFont(c.getFont());

if (fRotation == ROTATE_NONE)

{

int yPos = y + fCharHeight;

for (int i = 0; i < fCharStrings.length; i++)

{

int tweak;

switch (fPosition[i])

{

case POSITION_NORMAL:

g.drawString(fCharStrings[i], x

+ ((fWidth - fCharWidths[i]) / 2), yPos);

break;

case POSITION_TOP_RIGHT:

tweak = fCharHeight / 3;

g.drawString(fCharStrings[i], x + (tweak / 2), yPos

- tweak);

break;

case POSITION_FAR_TOP_RIGHT:

tweak = fCharHeight - fCharHeight / 3;

g.drawString(fCharStrings[i], x + (tweak / 2), yPos

- tweak);

break;

}

yPos += fCharHeight;

}

}

else if (fRotation == ROTATE_LEFT)

{

g.translate(x + fWidth, y + fHeight);

((Graphics2D) g).rotate(-NINETY_DEGREES);

g.drawString(fLabel, kBufferSpace, -fDescent);

((Graphics2D) g).rotate(NINETY_DEGREES);

g.translate(-(x + fWidth), -(y + fHeight));

}

else if (fRotation == ROTATE_RIGHT)

{

g.translate(x, y);

((Graphics2D) g).rotate(NINETY_DEGREES);

g.drawString(fLabel, kBufferSpace, -fDescent);

((Graphics2D) g).rotate(-NINETY_DEGREES);

g.translate(-x, -y);

}

}

public int getIconWidth()

{

return fWidth;

}

public int getIconHeight()

{

return fHeight;

}

public static int verifyRotation(String label, int rotateHint)

{

boolean hasCJK = false;

boolean hasMustRotate = false;

int len = label.length();

char data[] = new char[len];

char ch;

label.getChars(0, len, data, 0);

for (int i = 0; i < len; i++)

{

ch = data[i];

if ((ch >= '\u4E00' && ch <= '\u9FFF')

|| (ch >= '\u3400' && ch <= '\u4DFF')

|| (ch >= '\uF900' && ch <= '\uFAFF')

|| (ch >= '\u3040' && ch <= '\u309F')

|| (ch >= '\u30A0' && ch <= '\u30FF'))

hasCJK = true;

if ((ch >= '\u0590' && ch <= '\u05FF') ||

(ch >= '\u0600' && ch <= '\u06FF') ||

(ch >= '\u0700' && ch <= '\u074F'))

hasMustRotate = true;

}

if (hasCJK)

return DEFAULT_CJK;

int legal = hasMustRotate ? LEGAL_MUST_ROTATE : LEGAL_ROMAN;

if ((rotateHint & legal) > 0)

return rotateHint;

return hasMustRotate ? DEFAULT_MUST_ROTATE : DEFAULT_ROMAN;

}

static final StringsDrawsInTopRight= "\u3041\u3043\u3045\u3047\u3049\u3063\u3083\u3085\u3087\u308E"

+ // hiragana

"\u30A1\u30A3\u30A5\u30A7\u30A9\u30C3\u30E3\u30E5\u30E7\u30EE\u30F5\u30F6"; // katakana

static final StringsDrawsInFarTopRight= "\u3001\u3002";// comma,

// full

// stop

static final intDEFAULT_CJK= ROTATE_NONE;

static final intLEGAL_ROMAN= ROTATE_NONE | ROTATE_LEFT

| ROTATE_RIGHT;

static final intDEFAULT_ROMAN= ROTATE_RIGHT;

static final intLEGAL_MUST_ROTATE= ROTATE_LEFT | ROTATE_RIGHT;

static final intDEFAULT_MUST_ROTATE= ROTATE_LEFT;

static final doubleNINETY_DEGREES= Math.toRadians(90.0);

static final intkBufferSpace= 5;

public static void main(String args[]) {

JFrame fr = new JFrame("Test");

fr.getContentPane().add(testComponent());

fr.setSize(new Dimension(600, 400));

fr.setVisible(true);

fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

private static JComponent testComponent() {

JPanel panel = new JPanel();

panel.add(new JLabel(new VTextIcon(panel, "Hello Dear", VTextIcon.ROTATE_NONE)));

return panel;

}

}

Aniruddha-Herea at 2007-7-21 22:05:58 > top of Java-index,Desktop,Core GUI APIs...