This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.

S Dan

Greenhorn
+ Follow
since Apr 05, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by S Dan

Let consider the following line

List<DataType> result = Compute();

result is a list of type DataType and could be very large.
I need to keep this in memory as I'm using this list in the
other parts of the code and iterating over it. My application
could create a very large list at times and causes out of
memory exception. Setting max heap size using -Xmx will not
help in extreme cases. Basically I need to come up
with a smart scheme to manage the list that causes minimum
refactoring in my code. Any suggestions? Thanks.
-Dan
17 years ago
How can I change the height of the JFramHow to change the height of the JFrame title bar and its colore title bar and its color? Please don't suggest to change the height by changing the font size of the title bar..Thats a hack and doesn't look good at all. In general, is it possible to write a custom JFrame title bar? Working example will be appreciated. Thanks.
-Dan
18 years ago
I'm trying to reload a part of the jtree, where the node value has been changed (suppose the tree represents directory structure and the some file name has been modified under the root directory). The problem is that, each time I reload it, the tree collapses. I have an utility function to expand the tree but the problem is that the tree nodes changes (basically file names)quite frequently (every sec) and expanding the whole tree after each reload causing horrible flickering.
I tried reload(node), fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) , reload and all sort of relevant methods. But nothing works!! Can anyone tell me how to refresh a node of a tree without collapsing the whole tree.
From my google search, it seems that it is an open problem! I'd appreciate if you could provide me an working example.. As for example a FileTree where a file name change on your local machine will be reflected in that tree dynamically, without collapsing the tree.
Thanks.
-Dan
[ January 17, 2006: Message edited by: S Dan ]
19 years ago
Attached is the code that displays all unicode characters. The code is taken
from David Flanagan's book.
However this doesn�t display multiple East Asian languages at the same time.
Please compile it and run it

1. using �java �Duser.language=ja UnicodeDisplay�
2. using �java �Duser.language=zh UnicodeDisplay�

#1 will show the Japanese characters properly but won�t display the Chinese characters properly.
#2 will do just the reverse.

My question is, is there a way by which I can make this program display both Japanese and Chinese characters (if possible Korean too) at the same time.

By the way, there is a third party java software running on my machine that
displays all east asian languages properly. So I have those languages and fonts installed on my machine and thats definitely not the problem.

Thanks in advance for your help.
-Dan




import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
* This program displays Unicode glyphs using user-specified fonts
* and font styles.
**/
public class UnicodeDisplay extends JFrame implements ActionListener {
int page = 0;
UnicodePanel p;
JScrollBar b;
String fontfamily = "Serif";
int fontstyle = Font.PLAIN;

/**
* This constructor creates the frame, menubar, and scrollbar
* that work along with the UnicodePanel class, defined below
**/
public UnicodeDisplay(String name) {
super(name);
p = new UnicodePanel( ); // Create the panel
p.setBase((char)(page * 0x100)); // Initialize it
getContentPane( ).add(p, "Center"); // Center it

// Create and set up a scrollbar, and put it on the right
b = new JScrollBar(Scrollbar.VERTICAL, 0, 1, 0, 0xFF);
b.setUnitIncrement(1);
b.setBlockIncrement(0x10);
b.addAdjustmentListener(new AdjustmentListener( ) {
public void adjustmentValueChanged(AdjustmentEvent e) {
page = e.getValue( );
p.setBase((char)(page * 0x100));
}
});
getContentPane( ).add(b, "East");

// Set things up so we respond to window close requests
this.addWindowListener(new WindowAdapter( ) {
public void windowClosing(WindowEvent e) { System.exit(0); }
});

// Handle Page Up and Page Down and the up and down arrow keys
this.addKeyListener(new KeyAdapter( ) {
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode( );
int oldpage = page;
if ((code == KeyEvent.VK_PAGE_UP) ||
(code == KeyEvent.VK_UP)) {
if (e.isShiftDown( )) page -= 0x10;
else page -= 1;
if (page < 0) page = 0;
}
else if ((code == KeyEvent.VK_PAGE_DOWN) ||
(code == KeyEvent.VK_DOWN)) {
if (e.isShiftDown( )) page += 0x10;
else page += 1;
if (page > 0xff) page = 0xff;
}
if (page != oldpage) { // if anything has changed...
p.setBase((char) (page * 0x100)); // update the display
b.setValue(page); // and update scrollbar to match
}
}
});

// Set up a menu system to change fonts. Use a convenience method.
JMenuBar menubar = new JMenuBar( );
this.setJMenuBar(menubar);
menubar.add(makemenu("Font Family",
new String[ ] {"Serif", "SansSerif", "Monospaced"},
this));
menubar.add(makemenu("Font Style",
new String[ ]{
"Plain","Italic","Bold","BoldItalic"
}, this));
}

/** This method handles the items in the menubars */
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand( );
if (cmd.equals("Serif")) fontfamily = "Serif";
else if (cmd.equals("SansSerif")) fontfamily = "SansSerif";
else if (cmd.equals("Monospaced")) fontfamily = "Monospaced";
else if (cmd.equals("Plain")) fontstyle = Font.PLAIN;
else if (cmd.equals("Italic")) fontstyle = Font.ITALIC;
else if (cmd.equals("Bold")) fontstyle = Font.BOLD;
else if (cmd.equals("BoldItalic")) fontstyle = Font.BOLD + Font.ITALIC;
p.setFont(fontfamily, fontstyle);
}

/** A convenience method to create a Menu from an array of items */
private JMenu makemenu(String name, String[ ] itemnames,
ActionListener listener)
{
JMenu m = new JMenu(name);
for(int i = 0; i < itemnames.length; i++) {
JMenuItem item = new JMenuItem(itemnames[i]);
item.addActionListener(listener);
item.setActionCommand(itemnames[i]); // okay here, though
m.add(item);
}
return m;
}

/** The main( ) program just creates a window, packs it, and shows it */
public static void main(String[ ] args) {
UnicodeDisplay f = new UnicodeDisplay("Unicode Displayer");
f.pack( );
f.show( );
}

/**
* This nested class is the one that displays one "page" of Unicode
* glyphs at a time. Each "page" is 256 characters, arranged into 16
* rows of 16 columns each.
**/
public static class UnicodePanel extends JComponent {
protected char base; // What character we start the display at
protected Font font = new Font("serif", Font.PLAIN, 18);
protected Font headingfont = new Font("monospaced", Font.BOLD, 18);
static final int lineheight = 25;
static final int charspacing = 20;
static final int x0 = 65;
static final int y0 = 40;

/** Specify where to begin displaying, and redisplay */
public void setBase(char base) { this.base = base; repaint( ); }

/** Set a new font name or style, and redisplay */
public void setFont(String family, int style) {
this.font = new Font(family, style, 18);
repaint( );
}

/**
* The paintComponent( ) method actually draws the page of glyphs
**/
public void paintComponent(Graphics g) {
int start = (int)base & 0xFFF0; // Start on a 16-character boundary

// Draw the headings in a special font
g.setFont(headingfont);

// Draw 0..F on top
for(int i=0; i < 16; i++) {
String s = Integer.toString(i, 16);
g.drawString(s, x0 + i*charspacing, y0-20);
}

// Draw column down left.
for(int i = 0; i < 16; i++) {
int j = start + i*16;
String s = Integer.toString(j, 16);
g.drawString(s, 10, y0+i*lineheight);
}

// Now draw the characters
g.setFont(font);
char[ ] c = new char[1];
for(int i = 0; i < 16; i++) {
for(int j = 0; j < 16; j++) {
c[0] = (char)(start + j*16 + i);
g.drawChars(c, 0, 1, x0 + i*charspacing, y0+j*lineheight);
}
}
}

/** Custom components like this one should always have this method */
public Dimension getPreferredSize( ) {
return new Dimension(x0 + 16*charspacing,
y0 + 16*lineheight);
}
}
}
19 years ago
Ok, I already posted the similar message 2 times (with complete code example) but didn't get any response. Can a single java app support multiple locales (say chiense and japanese) at the same time? It seems not. Because when I set the
locale to japanese, my app doesn't show some chinese characters properly and when I set the locale to chinese, it messes with the japanese characters.
How can I display both chinese and japanese characters in one single application? Thanks in advanvce for your help.
-Dan
19 years ago
The following program tries to display a string that contains mostly japanese characters along with few chinese characters.
When I try "java I18NTest zh ZH" it shows all japanese and chinese characters properly except one.
When I try "java I18NTest ja JA" its shows the japanese fine but messes up the chinese characters.
What do I have to do so that it displays all japanese and chinese characters properly? Following is the java code and the .properties files (both the properties files are same though). I'm sure that the problem has nothing
to do with system fonts as there is a third party java application that shows those characters properly on my machine. Any help will really be appreciated.
Thanks.
-Dan

*******************************************************************
I18NTest.java

import javax.swing.*;
import java.awt.*;
import java.util.*;

public class I18NTest {
public static void main(String args[]) {

String language;
String country;

if (args.length != 2) {
language = new String("en");
country = new String("US");
} else {
language = new String(args[0]);
country = new String(args[1]);
}

Locale currentLocale;
ResourceBundle messages;

currentLocale = new Locale(language, country);
System.getProperties().put("user.language",language);
messages =
ResourceBundle.getBundle("MessagesBundle",currentLocale);

Object rows[][] = {
{"test", messages.getString("test")}
};
Object headers[] = {"L","R"};
JFrame frame = new JFrame("Sample");
JTable table = new JTable(rows, headers);
JScrollPane scrollPane = new JScrollPane(table);
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.setSize(300, 150);
frame.setVisible(true);
}
}
*******************************************************************
MessagesBundle_ja_JA.properties

test=\u4E2D\u56FD\u8BED\u9891\u9053\u3A00\u2000\u94C3\u6728
*******************************************************************
MessagesBundle_zh_ZH.properties

test=\u4E2D\u56FD\u8BED\u9891\u9053\u3A00\u2000\u94C3\u6728
19 years ago
Ok, the following program tries to display a string that contains mostly japanese characters along with few chinese characters.
When I try "java I18NTest zh ZH" it shows all japanese and chinese characters properly except one.
When I try "java I18NTest ja JA" its shows the japanese fine but messes up the chinese characters.
What do I have to do so that it displays all japanese and chinese characters properly? Following is the java code and the .properties files (both the properties files are same though). I'm sure that the problem has nothing
to do with system fonts as there is a third party java application that shows those characters properly on my machine. Any help will really be appreciated.
Thanks.
-Dan

*******************************************************************
I18NTest.java

import javax.swing.*;
import java.awt.*;
import java.util.*;

public class I18NTest {
public static void main(String args[]) {

String language;
String country;

if (args.length != 2) {
language = new String("en");
country = new String("US");
} else {
language = new String(args[0]);
country = new String(args[1]);
}

Locale currentLocale;
ResourceBundle messages;

currentLocale = new Locale(language, country);
System.getProperties().put("user.language",language);
messages =
ResourceBundle.getBundle("MessagesBundle",currentLocale);

Object rows[][] = {
{"test", messages.getString("test")}
};
Object headers[] = {"L","R"};
JFrame frame = new JFrame("Sample");
JTable table = new JTable(rows, headers);
JScrollPane scrollPane = new JScrollPane(table);
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.setSize(300, 150);
frame.setVisible(true);
}
}
*******************************************************************
MessagesBundle_ja_JA.properties

test=\u4E2D\u56FD\u8BED\u9891\u9053\u3A00\u2000\u94C3\u6728
*******************************************************************
MessagesBundle_zh_ZH.properties

test=\u4E2D\u56FD\u8BED\u9891\u9053\u3A00\u2000\u94C3\u6728


[ November 01, 2005: Message edited by: S Dan ]

[ November 01, 2005: Message edited by: S Dan ]
[ November 03, 2005: Message edited by: S Dan ]
19 years ago
any idea folks? I really need some help here
Thanks.
-Dan
19 years ago
Hi Stuart, that tutorial won't help me in this case. Please let me know if you have any other idea.
Thanks.
-Dan
19 years ago
I need to add some texts in the JFrame title bar that are in italics. How can I do that? I found that it is not accepting html string all.
Thanks
-Dan
[ October 04, 2005: Message edited by: S Dan ]
19 years ago
Also, how do I change the height of JFrame title bar height?
Thanks.
-Dan
19 years ago
How do I change the JFrame title bar color from default blue to a different color? A tested code snippet will be appreciated.
Thanks.
-Dan
19 years ago
Very cool idea. Thanks!
19 years ago
I'm adding I18N feature to my app. I'd like my app to be able to update the language in the GUI dynamically when user chooses a particular language. Suppose the initial language (whe the app starts)is US_EN. Now I have a language panel (from my apps options menu) that consists of several languags in the form or radio button. User chooses one of the language from
the pannel (say japanese)and hit update button. Now, I'd like the GUI to update the language from resourcebundle automatically and display it..
One way of doing that would be, updating all the labels,tooltiptext etc. in your GUI from the modified resourcebundle, programatically. However that might require signifact amout of coding depending on how many places you need to make those changes..
My question is, is there a better way of getting the job done?
Thanks in advance.
-Dan
19 years ago
Thanks Michael. But could you please provide a complete working example? I'm still having some problems with this..
Thanks.
-Dan
19 years ago