| checkbox ploblem pls help!! |
|
 |
Index ‹ java-programmer
|
- Previous
- 3
- XMLEncoder & DefaultPersistenceDelegateI am trying to encode EventObject's as XML using XMLEncoder. As
subclasses of EventObject/AWTEvent are generally NOT java beans (they
do not provide a nullary constructor), I have to provide an instance of
DefaultPersistenceDelegate which specifies which properties are set by
the constructor. I tried to this with ActionEvent as follows:
encoder.setPersistenceDelegate( ActionEvent.class, new
DefaultPersistenceDelegate(
new String[] {"source", "ID", "actionCommand", "modifiers",
"when"} )
);
Unfortunately, when I call encoder.writeObject with an argument of type
ActionEvent, I get the following exception:
java.lang.NoSuchMethodException: <unbound>=Class.new(null, Integer,
"1", Integer, Long);
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement
XMLEncoder.writeObject(ActionEvent);
Continuing ...
It is apparently unable to find the constructor due to the first
argument being null. However, "source" in my ActionEvent happens to not
be null. "source" is a property from EventObject rather than
ActionEvent, and I think this may be part of the problem. I have read
another post that says XMLEncoder has problems with superclass
properties.
Anybody have any ideas?
- 3
- JTable row selection (left and right mouse)Is it possible to be able to allow users to use either the left or the right
mouse button to select one or more
rows in a JTable, and upon the selection, be able to tell which mouse button
they used to select the row(s)?
I have 15 tables on the screen. The user needs to select one or more rows
from one table (the source)
and then the same number of rows in another table (the destination) and then
I need to swap the row
data from both tables. So, I need a way to differentiate between the
selections on the source and the
destination tables.
Thank you.
- 3
- HalfTruth=Lie (was: I'm still waiting for somebody to offer co...)> From: "Phlip" <email***@***.com>
> The good is the enemy of the best.
A half-truth is a lie.
A bicycle with only one wheel isn't useful.
Yin without yang isn't useful.
A glass half full but not half empty, or vice versa, is not the whole
picture.
For nearly every cliche there's an opposite which is equally valid in
different circumances.
Please choose which of the following activities you would most and
least like to participate in:
(1) Have bamboo shoots driven up under your fingernails.
(2) Undergo Chinese water torture.
(3) Be trapped in a large tank with one (1) pihrana.
- 3
- External process output missingHello,
I'm using Runtime.getRuntime().exec(procedureFile) to run external
system commands stored in procedure files, and I get their output from
process.getInputStream().
This works OK in Windows, but when I try it in a Unix system I get the
direct output (i.e. procedure echos) but not the output from the
programs run by the procedure. For example:
#!/bin/sh
PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/sysadm/bin:
export PATH
echo "Starting remote copy for $1"
scp -r $1 map@remotehost:/apps/myapp
echo "End of remote copy for $1"
would return the two echo messages, but not the output from scp.
Is there something that must be done or declared to get all the output
in Unix?
Thanks for any hint,
Guifre
- 4
- How do I open a device in non-blocking mode?I'm a little stuck. I have a Linux device (a character device, like a
serial port) called /dev/cm15a0. I can't use RXTXcomm as it doesn't
recognize the device (and I'm having trouble recompile RXTX). I need
to open the device in non-blocking mode and read and write bytes
to/from the device. Any pointers?
--
Linux Home Automation Neil Cherry email***@***.com
http://www.linuxha.com/ Main site
http://linuxha.blogspot.com/ My HA Blog
Author of: Linux Smart Homes For Dummies
- 4
- JAVA ?Oracle Programmers wantedHighly experienced JAVA / Oracle programmers wanted for a three month
contract in South Africa (JHB). Must have had ERP experience with some
integration skills.Open source experience an added advantage. Must be able
to work in a team.
Email CV to email***@***.com
- 4
- PropertyChangeListener not recognizing changes to a putClientPropertyI must be missing out on something fundamental . . . why doesn't the
following code ever register a PropertyChangeEvent?
import java.beans.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.text.*;
public class PropTest extends JFrame {
private Boolean myBoolean = Boolean.FALSE;
public PropTest() {
super("PropertyChangeListener Test");
JPanel panel = new JPanel();
JButton button = new JButton(new BooleanAction("Button pushed"));
button.setText("Push me!");
panel.putClientProperty("myBoolean", myBoolean);
panel.addPropertyChangeListener("myBoolean", new BooleanListener());
panel.add(button);
panel.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0),
"space");
panel.getActionMap().put("space", new BooleanAction("Space
pressed"));
this.getContentPane().add(panel);
}
private class BooleanAction extends AbstractAction {
String title;
public BooleanAction(String title) {
super();
this.title = title;
}
public void actionPerformed(ActionEvent e) {
System.out.println(title);
System.out.println("Old value: " + myBoolean.toString());
myBoolean = new Boolean(!myBoolean.booleanValue());
System.out.println("New value: " + myBoolean.toString());
}
}
private class BooleanListener implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent e) {
System.out.println("Hey, you changed my value!");
}
}
public static void main(String[] args) {
PropTest propTest = new PropTest();
propTest.setResizable(false);
propTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
propTest.pack();
propTest.setVisible(true);
}
}
- 5
- Static fields accessed by getter/setter...what happens?(apology for duplicate post, I felt I posted in the wrong forum earlier.)
Could someone please enlighten me as to what will happen if I have:
public class MyClass
{
public static String someName = null;
public void setSomeName(String s)
{
someName = s;
}
public void getSomeString()
{
return someString;
}
}
I'm not sure how the static field is being handle using non-static getters/setters.
Thanks
Stacey
- 6
- Configuring Tomcat to NOT use webapps directorycurrently my webapps directory is something like:
C:\java\netbeans3.5.1\tomcat406\webapps
This is where the Netbeans install put it. I want to move the
directory to something a little more convenient to work with like:
c:\webapps
All I can find in the Tomcat configuration file is:
<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true">
but if I change appBase to anything like "c:\webapps" or "c:/webapps"
it doesn't work. Can anybody tell me how to move the appBase
directory outside of the Tomcat or Netbean directory?
Thanks in advance.
Dean
- 6
- Is it possible to write an applet that reads image and data files from web server that is easy for end users?My background:
4th year computer science student.
The school that I am studying at teaches a lot of java, but they haven't
ever touched upon applets. I don't have much experiance with applets and
I find that applets are excercising my patience. I thought I would
attempt to write an involved applet and the program I was writing was
working very well and I was pleased with the way it as coming out. I
then put it on a web server and discovered all of the security problems
with running applets off of the web. I am at a point now where I might
want to totally abandon the project using java and move over to c++ and
just write an app that uses an exe.
I have done a lot of searching on the net for the info that seems to be
eluding me. I am searching for and It is not clear to me if I can do
what I wish to do without all of the damn security exceptions.
My main question:
I want to develop an application that runs from a browser window as an
applet using Java. I want to be able to read files from the same server
and directory structure which has the html files. The files that I would
be reading would be jpg's and gif's and either text files or binary
files for the data. It would also be nice to write to the directory, but
at this point I would just be satisfied to be able to just read files.
The users that I expect to use this applet are not expected to be very
competant computer users. It is very important that the applet just run
from a link or other simple method. Can I do this from a jar file
without having to use certificates and/or java policy file
modifications.
I don't want to give up on java just yet, but this security thing is
killing it for me.
I have even thought about planting the data within the source code, but
that to me seems too damn messy, and just plain wrong.
I would just like if people could tell me one way or another if my
program would be possible.
Jean-Paul Lanaux
- 9
- Changing button colors in a loopHi all:
I am working on a task that should imitate an elevator. I have two vertical
rows of round buttons "Up" and "Down" When a circle is selected randomly by
the program, the circle becomes yellow and the elevator moves to that
button.
Here is what I did:
1. created a class Circle where I save buttons' parameters
2. saved Circle objects in an array
3. drew the buttons depending on their parameters
4. generated a random number, matched it with an array index and assigned
the object color to yellow.
Everything is fine except that I can't figure out how to change colors of my
buttons in a loop. Help would be greatly appreciated!
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class Elevator3 extends JPanel
{
private int n = 40;
private int width = 200;
private int floors = 10;
private int interval = 1000;
private boolean selected = false;
private Circle[] buttons = new Circle[2*(floors-1)];
public Elevator3()
{
build();
JFrame frame = new JFrame("Elevator3");
setBackground(Color.WHITE);
setFont(new Font("SansSerif", Font.PLAIN, Math.round(n/3)));
frame.getContentPane().add(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, n*(floors+2) );
frame.setVisible(true);
}
public void build()
{
Random r = new Random();
int buttonPick;
int timeUntilNextButton = r.nextInt(interval);
for (int k =0; ; k++)
{
if (timeUntilNextButton-- ==0)
{
buttonPick = r.nextInt(2*(floors-1));
//populate my buttons array here - how??
timeUntilNextButton = r.nextInt(interval);
}
}
//adding "Down" buttons
for (int i=1, count=0; i < floors; i++, count++)
{
if (count == buttonPick)
selected = true;
else
selected = false;
buttons[count]= new Circle(n*2, n*i, selected, Math.round(n/2));
}
//build an array of "Up" circles
for (int i=2, count=floors-1; i < floors+1; i++, count++)
{
if (count == buttonPick)
selected = true;
else
selected = false;
buttons[count]= new Circle(n, n*i, selected, Math.round(n/2));
}
}
public static void main(String[] args)
{
new Elevator3();
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
//draw buttons
for (int i=0; i < buttons.length; i++)
{
g.setColor(buttons[i].getColor());
g.fillOval(buttons[i].getX(), buttons[i].getY(),
buttons[i].getWidth(), buttons[i].getWidth());
}
}
}
class Circle
{
private int x;
private int y;
private Color c;
private boolean pressed;
private int width;
public Circle(int xCoordinate, int yCoordinate, boolean selected,
int diameter)
{
x = xCoordinate;
y = yCoordinate;
pressed = selected;
width = diameter;
if (pressed)
c = Color.YELLOW;
else
c = Color.LIGHT_GRAY;
}
public Color getColor()
{
return c;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public int getWidth()
{
return width;
}
}
- 10
- class not found within IEHi,
I've written an applet. It properly works with Mozila. But with
Internet Explorer it says "Class [the applet's name] not found" or
something.
What is the problem? How can I fix it?
Thank you,
Siamak
- 15
- JavaDoc Ignore TagsHi all,
Is it possible to tel JavaDoc to ignore certain XDocLet tags, and/or not raise a warning that it is
unknown?
I am currently running JavaDoc through an Ant task, and wish to hide the warnings about my
@hibernate tags.
Regards,
--
- 15
- sample jsp servlet application requiredHi geeks,
I'm a beginner in jsp and servlets, i want a sample JSP-SERVLET
applicaton with source code. Can you please tell me where can i get the
sample applications.
Thanks in advance...
- 15
- history.back problem with firefoxHi,
I have 2 submit buttons in a jsp page. One of them takes me to
page2.jsp and also passes the values enetered to page2.I have a link
in the page2 that does a history.back to come to the previous page to
make any chnages necessary. Now after making my changes, instead of
going to page2.jsp if I want to submit the page, Instead of submitting
the page it takes me to page2.jsp again.
This problem is only with firefox. It works fine with IE. Can anyone
help me on this?
|
| Author |
Message |
yew y via JavaKB.com

|
Posted: 2005-3-30 10:50:00 |
Top |
java-programmer, checkbox ploblem pls help!!
i was new in java and i now completed add the checkbox in each node but the
ploblem is i cant click the check box..
what should i do in next step... pls help me thank you..
following is my code
fileTree.setCellRenderer(new DefaultTreeCellRenderer()
{
public Component getTreeCellRendererComponent(JTree tree, Object
value,
boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
{
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
row, hasFocus);
JCheckBox chk = new JCheckBox();
chk.setContentAreaFilled(false);
chk.setEnabled(true);
//
chk.setBorderPaintedFlat(true);
chk.setOpaque(false);
JPanel jPanel = new JPanel(new BorderLayout());
jPanel.add(chk, BorderLayout.WEST);
jPanel.add(this, BorderLayout.EAST);
return jPanel;
}
--
Message posted via http://www.javakb.com
|
| |
|
| |
 |
usenet

|
Posted: 2005-3-30 22:03:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
yew y via JavaKB.com <email***@***.com> wrote:
> i was new in java and i now completed add the checkbox in each node but the
> ploblem is i cant click the check box..
> what should i do in next step... pls help me thank you..
* Read the documentation and tutorial.
* Also write a TreeCellEditor.
Christian
|
| |
|
| |
 |
yew y via JavaKB.com

|
Posted: 2005-3-31 16:20:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
how can i cal the tree in cell editor??
--
Message posted via http://www.javakb.com
|
| |
|
| |
 |
usenet

|
Posted: 2005-3-31 23:47:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
yew y via JavaKB.com <email***@***.com> wrote:
> how can i cal the tree in cell editor??
Please be a lot more specific.
Christian
|
| |
|
| |
 |
yew y via JavaKB.com

|
Posted: 2005-4-4 9:42:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
how can i write the tree cell renderer?
--
Message posted via http://www.javakb.com
|
| |
|
| |
 |
usenet

|
Posted: 2005-4-4 19:46:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
yew y via JavaKB.com <email***@***.com> wrote:
> how can i write the tree cell renderer?
Please quote what you are referring to.
Please look up the meaning of "specific".
Please post the code you've written, describing what it should do and
what it does etc.
Christian
|
| |
|
| |
 |
yew y via JavaKB.com

|
Posted: 2005-4-5 11:23:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
can u giv me ur e-mail so i can send the code for you..
thank you
--
Message posted via http://www.javakb.com
|
| |
|
| |
 |
usenet

|
Posted: 2005-4-6 23:12:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
yew y via JavaKB.com <email***@***.com> wrote:
> can u giv me ur e-mail so i can send the code for you..
Please quote the text you are referring to.
I see no reason to switch te discussion to mail.
Christian
|
| |
|
| |
 |
yew y via JavaKB.com

|
Posted: 2005-4-11 11:25:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
tis is my renderer n editor..
y my checkbox still can't click?
public class TestEditor1 implements TreeCellEditor
{
public TestEditor1()
{ }
public void addCellEditorListener(CellEditorListener l)
{ }
public void cancelCellEditing()
{ }
public Object getCellEditorValue()
{
return this;
}
public boolean isCellEditable(EventObject evt)
{
if (evt instanceof MouseEvent)
{
MouseEvent mevt = (MouseEvent) evt;
if (mevt.getClickCount() == 1)
{
return true;
}
}
return false;
}
public void removeCellEditorListener(CellEditorListener l)
{ }
public boolean shouldSelectCell(EventObject anEvent)
{
return true;
}
public boolean stopCellEditing()
{
return false;
}
public Component getTreeCellEditorComponent(JTree tree,
Object value,
boolean isSelected,
boolean expanded,
boolean leaf,
int row)
{
DefaultMutableTreeNode temp = (DefaultMutableTreeNode) value;
JCheckBox temp2=(JCheckBox)temp.getUserObject();
return temp2;
}
}
public class CkBoxRenderer extends DefaultTreeCellRenderer
{
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
{
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,
hasFocus);
JCheckBox chk = new JCheckBox();
chk.setContentAreaFilled(true);
chk.setEnabled(true);
chk.setBackground(UIManager.getColor("Tree.textBackground"));
JPanel jPanel = new JPanel(new BorderLayout());
jPanel.add(chk, BorderLayout.WEST);
jPanel.add(this, BorderLayout.EAST);
return jPanel;
}
}
--
Message posted via http://www.javakb.com
|
| |
|
| |
 |
usenet

|
Posted: 2005-4-13 0:27:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
yew y via JavaKB.com <email***@***.com> wrote:
> tis is my renderer n editor..
> y my checkbox still can't click?
a b c u i s?
> public class TestEditor1 implements TreeCellEditor
Why are you not subclassing AbstractCellEditor? Your implementation for
most methods are wrong.
> public Object getCellEditorValue()
> {
> return this;
> }
The value of the cell editor is the value to be stored in the model. It
hardly makes sense that this is the cell editor itself.
> public Component getTreeCellEditorComponent(JTree tree,
> Object value,
> boolean isSelected,
> boolean expanded,
> boolean leaf,
> int row)
> {
> DefaultMutableTreeNode temp = (DefaultMutableTreeNode) value;
> JCheckBox temp2=(JCheckBox)temp.getUserObject();
> return temp2;
Neither does it make much sense to use JCheckBox as value. JCheckBox
can be used to present to the value, but the value itself should be
a proper abstraction.
> public class CkBoxRenderer extends DefaultTreeCellRenderer
> {
> public Component getTreeCellRendererComponent(JTree tree, Object value,
> boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
> {
> super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,
> hasFocus);
>
> JCheckBox chk = new JCheckBox();
>
> chk.setContentAreaFilled(true);
> chk.setEnabled(true);
> chk.setBackground(UIManager.getColor("Tree.textBackground"));
> JPanel jPanel = new JPanel(new BorderLayout());
> jPanel.add(chk, BorderLayout.WEST);
> jPanel.add(this, BorderLayout.EAST);
> return jPanel;
This does not make much sense either. Why are you creating a new checkbox
instead of using the "value"?
Christian
|
| |
|
| |
 |
yew y via JavaKB.com

|
Posted: 2005-4-14 9:53:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
so wat should i do to make my checkbox can click?
can you teach me??
tis is very urgent!!!
--
Message posted via http://www.javakb.com
|
| |
|
| |
 |
yew y via JavaKB.com

|
Posted: 2005-4-14 9:54:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
i really no idea to do .......
i really not familiar with swing.....
hope you can help me..
thank in advanced...
--
Message posted via http://www.javakb.com
|
| |
|
| |
 |
usenet

|
Posted: 2005-4-18 3:44:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
yew y via JavaKB.com <email***@***.com> wrote:
> i really no idea to do .......
> i really not familiar with swing.....
> hope you can help me..
> thank in advanced...
Try to understand the following code. Also try to figure out its
limitations.
import javax.swing.AbstractCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JTree;
import javax.swing.tree.TreeCellEditor;
import javax.swing.tree.TreeCellRenderer;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.UIManager;
class CheckBoxEditor
extends AbstractCellEditor
implements TreeCellEditor
{
private JCheckBox box;
public CheckBoxEditor()
{
box = new JCheckBox();
box.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
stopCellEditing();
}
});
}
public Component getTreeCellEditorComponent
(JTree t, Object value, boolean selected, boolean expanded, boolean leaf, int row)
{
box.setForeground(t.getForeground());
box.setBackground(t.getBackground());
box.setComponentOrientation(t.getComponentOrientation());
box.setEnabled(t.isEnabled());
// these two lines
box.setText(value.toString().substring(1));
box.setSelected(value.toString().charAt(0) == 'x');
return box;
}
public Object getCellEditorValue()
{
// this line
return (box.isSelected() ? "x" : "/") + box.getText();
}
}
class CheckBoxRenderer
extends JCheckBox
implements TreeCellRenderer
{
private Color selectionForeground, selectionBackground;
private boolean painting, focused;
public CheckBoxRenderer()
{
setHorizontalAlignment(LEADING);
setContentAreaFilled(true);
selectionForeground = UIManager.getColor("Tree.selectionForeground");
selectionBackground = UIManager.getColor("Tree.selectionBackground");
}
public Component getTreeCellRendererComponent
(JTree t, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean focused)
{
if (false && selected)
{
setForeground(selectionForeground);
setBackground(selectionBackground);
}
else
{
setForeground(t.getForeground());
setBackground(t.getBackground());
}
this.focused = focused;
setComponentOrientation(t.getComponentOrientation());
setEnabled(t.isEnabled());
// these two lines
setText(value.toString().substring(1));
setSelected(value.toString().charAt(0) == 'x');
return this;
}
protected void paintComponent(Graphics g)
{
{
painting = true;
}
try
{
super.paintComponent(g);
}
finally
{
painting = false;
}
}
public boolean hasFocus()
{
return painting ? focused : super.hasFocus();
}
}
class CheckBoxTest
{
public static void main(String[] args)
{
JTree t = new JTree();
t.setCellRenderer(new CheckBoxRenderer());
t.setCellEditor(new CheckBoxEditor());
t.setEditable(true);
javax.swing.JFrame f = new javax.swing.JFrame();
f.getContentPane().add(new javax.swing.JScrollPane(t));
f.setSize(500, 400);
f.setVisible(true);
}
}
|
| |
|
| |
 |
yew y via JavaKB.com

|
Posted: 2005-4-18 11:33:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
firstly i want to say thank you... my checkbox clickable..
but still hav ploblem is my checkbox can click but my 1st charactar of my
data already gone lah.... wat is the ploblem.... how can i set the
clickable value to perform action.....
--
Message posted via http://www.javakb.com
|
| |
|
| |
 |
usenet

|
Posted: 2005-4-19 1:06:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
yew y via JavaKB.com <email***@***.com> wrote:
> firstly i want to say thank you... my checkbox clickable..
> but still hav ploblem is my checkbox can click but my 1st charactar of my
> data already gone lah.... wat is the ploblem.... how can i set the
> clickable value to perform action.....
Please quote some context.
1. That is the way the data is stored. In this simple example,
the first character encodes whether the data is checked.
2. ActionListener?
Christian
|
| |
|
| |
 |
yew y via JavaKB.com

|
Posted: 2005-4-19 10:49:00 |
Top |
java-programmer >> checkbox ploblem pls help!!
this is my full program tree.... is use for show the full path of the
directory.... i need to add chkbox beside to perform action
getSelectionMode() or getCellEditorValue() or action listener... i still
confuse....
from ur example , my checkbox already can click but the 1st character is
gone... can you solve tis ploblem?
/**
DirTree (former FileTree1)
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
public class DirTree
extends JPanel {
public static final String APP_NAME = "Directories Tree";
public static final ImageIcon ICON_COMPUTER =
new ImageIcon("computer.gif");
public static final ImageIcon ICON_DISK =
new ImageIcon("disk.gif");
public static final ImageIcon ICON_FOLDER =
new ImageIcon("folder.gif");
public static final ImageIcon ICON_EXPANDEDFOLDER =
new ImageIcon("expandedfolder.gif");
protected JTree m_tree;
protected DefaultTreeModel m_model;
protected JTextField m_display;
public DirTree() {
DefaultMutableTreeNode top = new DefaultMutableTreeNode(
new IconData(ICON_COMPUTER, null, "My Computer"));
DefaultMutableTreeNode node;
File[] roots = File.listRoots();
for (int k=0; k<roots.length; k++) {
node = new DefaultMutableTreeNode(new IconData(ICON_DISK,
null, new FileNode(roots[k])));
top.add(node);
node.add( new DefaultMutableTreeNode(new Boolean(true)));
}
m_model = new DefaultTreeModel(top);
m_tree = new JTree(m_model);
m_tree.putClientProperty("JTree.lineStyle", "Angled");
m_tree.addTreeExpansionListener(new
DirExpansionListener());
m_tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
m_tree.setShowsRootHandles(true);
m_tree.setEditable(true);
JScrollPane splitPane = new JScrollPane(
new JScrollPane(m_tree)
);
setLayout( new BorderLayout() );
add( splitPane );
}
DefaultMutableTreeNode getTreeNode(TreePath path) {
return (DefaultMutableTreeNode)(path.getLastPathComponent());
}
FileNode getFileNode(DefaultMutableTreeNode node) {
if (node == null)
return null;
Object obj = node.getUserObject();
if (obj instanceof IconData)
obj = ((IconData)obj).getObject();
if (obj instanceof FileNode)
return (FileNode)obj;
else
return null;
}
// Make sure expansion is threaded and updating the tree model
// only occurs within the event dispatching thread.
class DirExpansionListener implements TreeExpansionListener {
public void treeExpanded(TreeExpansionEvent event) {
final DefaultMutableTreeNode node = getTreeNode(
event.getPath());
final FileNode fnode = getFileNode(node);
Thread runner = new Thread() {
public void run() {
if (fnode != null && fnode.expand(node)) {
Runnable runnable = new Runnable() {
public void run() {
m_model.reload(node);
}
};
SwingUtilities.invokeLater(runnable);
}
}
};
runner.start();
}
public void treeCollapsed(TreeExpansionEvent event) {}
}
public static void main(String argv[]) {
JFrame frame= new JFrame( "FileSystem Viewer");
DirTree dir = new DirTree();
frame.getContentPane().add(dir);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
class IconData {
protected Icon m_icon;
protected Icon m_expandedIcon;
protected Object m_data;
public IconData(Icon icon, Object data) {
m_icon = icon;
m_expandedIcon = null;
m_data = data;
}
public IconData(Icon icon, Icon expandedIcon, Object data) {
m_icon = icon;
m_expandedIcon = expandedIcon;
m_data = data;
}
public Icon getIcon() {
return m_icon;
}
public Icon getExpandedIcon() {
return m_expandedIcon!=null ? m_expandedIcon : m_icon;
}
public Object getObject() {
return m_data;
}
public String toString() {
return m_data.toString();
}
}
class FileNode {
protected File m_file;
public FileNode(File file) {
m_file = file;
}
public File getFile() {
return m_file;
}
public String toString() {
return m_file.getName().length() > 0 ? m_file.getName() :
m_file.getPath();
}
// Alternatively we copud sub-class TreeNode
public boolean expand(DefaultMutableTreeNode parent) {
DefaultMutableTreeNode flag =
(DefaultMutableTreeNode)parent.getFirstChild();
if (flag==null) // No flag
return false;
Object obj = flag.getUserObject();
if (!(obj instanceof Boolean))
return false; // Already expanded
parent.removeAllChildren(); // Remove Flag
File[] files = listFiles();
if (files == null)
return true;
Vector v = new Vector();
for (int k=0; k<files.length; k++) {
File f = files[k];
if (!(f.isDirectory()))
continue;
FileNode newNode = new FileNode(f);
boolean isAdded = false;
for (int i=0; i<v.size(); i++) {
FileNode nd = (FileNode)v.elementAt(i);
if (newNode.compareTo(nd) < 0) {
v.insertElementAt(newNode, i);
isAdded = true;
break;
}
}
if (!isAdded)
v.addElement(newNode);
}
for (int i=0; i<v.size(); i++) {
FileNode nd = (FileNode)v.elementAt(i);
IconData idata = new IconData(DirTree.ICON_FOLDER,
DirTree.ICON_EXPANDEDFOLDER, nd);
DefaultMutableTreeNode node = new
DefaultMutableTreeNode(idata);
parent.add(node);
if (nd.hasSubDirs())
node.add(new DefaultMutableTreeNode(
new Boolean(true) ));
}
return true;
}
public boolean hasSubDirs() {
File[] files = listFiles();
if (files == null)
return false;
for (int k=0; k<files.length; k++) {
if (files[k].isDirectory())
return true;
}
return false;
}
public int compareTo(FileNode toCompare) {
return m_file.getName().compareToIgnoreCase(
toCompare.m_file.getName() );
}
protected File[] listFiles() {
if (!m_file.isDirectory())
return null;
try {
return m_file.listFiles();
}
catch (Exception ex) {
JOptionPane.showMessageDialog(null,
"Error reading directory "+m_file.getAbsolutePath(),
DirTree.APP_NAME, JOptionPane.WARNING_MESSAGE);
return null;
}
}
}
--
Message posted via http://www.javakb.com
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Applets and J2SE 5.0 - problems?I set my IE browser (corporate edict to use IE...ugh)
to use the 9/30 FCS release of 5.0
Whenever I visit a page with an applet, the browser
crashes.
Someone at our local user group (www.javasig.com)
mentioned something about version mismatches (???).
Anyone else experience this?
btw, kudos to Calvin Austin (J2SE 5.0 spec lead) and
the rest for a very organized and efficient release.
Frank G.
+==========================================+
| Crossroads Technologies Inc. |
| www.CrossroadsTech dot com |
| fgreco at REMOVE!cross!roads!tech!dot com|
+==========================================+
- 2
- Balanced TreeI was wondering if there were a built in (or freely available) library for
handling balanced trees.
I find many projects use them or could benefit from them.
:)
- 3
- JTable and associating objects with nodesHi,
Does anyone know how to store objects in a name value pair data structure
(i.e. hashmap) in a JTable? It easy to store the name of the object but to
store the object with the name, I am not sure.
Any help would be great
Thanks
Bob
- 4
- File upload with JSF.....Hi,
i'm a new user of java. I have a question. I have to develop a JSF
application that make user able to:
1) Upload a txt file
2) Showing to user columns and rows numbers of file.
For this second operation i'have developed a java application that
receive a txt file from a BufferedReader and counts rows and columns
number.
My questions are:
1) How can i realize file upload with JSF?
2) In which format a file is uploaded?
3) Can i use my java application for counting rows and columns number
of file?
Can you help me?Please use easy concepts because i'm inexpert.....
- 5
- How to control the cursor positon of java program in console mode?I am writing a small database that requires user input.
However, whenever something is output to the screen, the cursor stays at the
beginning of the output instead of the end of the output.
How can I let it go to the end of the output?
For example:
say, the output is like this:
This is a database. Please input your information below.
prompt:>
I want the cursor to go to after the ">" sign but it stays in front of
"this" although whenever the user presses the keyboard it goes the end after
">".
This is not a big problem but makes my application look not so professional.
Anyway to cure this?
John
- 6
- XML Validation problemI am having alot of trouble getting a XML document validated with a
schema.
I got a sample document and schema off of w3schools.com, which passed
an online xml validator:
http://tools.decisionsoft.com/schemaValidate.html. I cannot, however,
get them validated programmatically.
The documents are:
node.xsd:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified"><xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element></xs:schema>
node.xml:
<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
I'm using java 1.5 currently, although I had problems with 1.4 and
xerces, so I'm pretty confident the problem isn't related to the java
version.
My code is:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setIgnoringElementContentWhitespace(true);
factory.setIgnoringComments(true);
SchemaFactory sFact =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setSchema(sFact.newSchema(new java.io.File(SCHEMA_FILE)));
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new ErrorHandler() {
public void warning (SAXParseException exception) throws SAXException
{
System.err.println(exception);
}
public void error (SAXParseException exception) throws SAXException {
System.err.println(exception);
}
public void fatalError (SAXParseException exception) throws
SAXException {
System.err.println(exception);
}
});
org.w3c.dom.Document doc = builder.parse(file);
The error I recieve is:
org.xml.sax.SAXParseException:
http://www.w3.org/TR/xml-schema-1#cvc-elt.1?note
org.xml.sax.SAXParseException:
http://www.w3.org/TR/xml-schema-1#cvc-elt.1?note
Exception in thread "main" java.lang.IllegalStateException
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl$3.checkState(ValidatorHandlerImpl.java:411)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl$3.getElementTypeInfo(ValidatorHandlerImpl.java:441)
at com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent$SAX2XNI.elementAug(JAXPValidatorComponent.java:299)
at com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent$SAX2XNI.endElement(JAXPValidatorComponent.java:291)
at com.sun.org.apache.xerces.internal.jaxp.XNI2SAX.endElement(XNI2SAX.java:163)
at com.sun.org.apache.xerces.internal.jaxp.validation.XNI2SAXEx.endElement(XNI2SAXEx.java:108)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:818)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.endElement(ValidatorHandlerImpl.java:339)
at com.sun.org.apache.xerces.internal.jaxp.XNI2SAX.endElement(XNI2SAX.java:163)
at com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent.endElement(JAXPValidatorComponent.java:206)
at com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler.endElement(XIncludeHandler.java:790)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1241)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:248)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:169)
...
I am behind a web proxy, and I don't know if the validation process
involves retrieving files at the URLs in the xml and xsd files, which
could be the problem.
can someone shed some light on this?
Thanks in advance.
- 7
- using parameterized ArrayListI am trying to read write <Event> objects to an ArrayList ... but when
I try to convert the arraylist back to the object arrayit gives me a
ClassCastException for the line
return (Event[]) a.toArray();
--------------------------------------
BufferedReader ois = null;
ArrayList<Event> a = new ArrayList<Event>();
try {
ois = new BufferedReader(new FileReader(this.calFile));
Event e = null;
String line;
while ((line = ois.readLine()) != null) {
e = new Event(line);
a.add(e);
}
ois.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (InvalidTimeRangeException e) {
e.printStackTrace();
}
if (a.isEmpty())
return null;
return (Event[]) a.toArray();
- 8
- 'back engineering' java appletshi,
is it possible to gain access to java code by a user using an applet over
the web? i know with some scripting languages like PHP or javascript then
users can view the code and 'back engineer' it to discover how it works etc.
is this possible with java?
thanks
- 9
- Eclipse: browsing sourcecode using { as marksHello everyone,
I am using eclipse 3.0.2 on Linux. Is it possible to browse
Java-sourcecode using the brackets { as a jumping point?
example
public void foo(){ <- first entry
if(isFoo){ <- second entry
doFoo();
}else{ <- third entry
doAnotherFoo();
}
thanks alot for any help!
kind regards
Oliver
- 10
- butting components right up against each otherOn Fri, 27 Jun 2003 13:29:59 GMT, Roedy Green <email***@***.com> wrote:
> On Fri, 27 Jun 2003 14:06:22 +0100, Daniel Dyer
> <email***@***.com> wrote or quoted :
>
>> Sorry, I didn't mean ipadx/ipady, that won't help. You certainly
>> shouldn't need to use absolute positioning though. Do you have any
>> sample code to show us?
> I just wanted to put a string of JTextFields with black backgrounds
> right against each other so they look like one continuous field.
Have you tried setting the borders on the text fields to null? Maybe it's
the borders that make it look like there's a gap. Have you tried a
different layout (maybe try GridLayout, just to see if it looks the same,
it's much simpler so it will be easier to spot if you've done something
wrong).
Dan.
--
Daniel Dyer
Empathy Software (http://www.empathysoftware.com)
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
- 11
- newbie: Global EJB and more ...
Hi group,
While thinking of how to transfer a tranditional client-server app
into J2EE, I got following two questions:
1, In a typical application, there should be some global (even
singleton) objects which are created on application startup code and
stay there until the program exiting. In the idiom of J2EE, what kind
of Beans act like this kind of global object? And, when and how these
global beans should be created?
2, I knew Beans have to be deployed onto the server before they come
to be available, but those Beans quit often need some objects to
complete its job, these objects may encapsulate a algorithem, may do
some management task, but they typically dont have to exposed to
client tire or web tire. I call these objects are intermediate
objects. My question is, should this kind of objects need to be a EJB?
My J2EE books seems only to mention three kinds of Beans,
SessionBeans, EntityBeans and MessageBeans. But what do I do for those
intermediate objects?
Thanks in advance.
--
email***@***.com
%% (fortunes)
Q: How did you get into artificial intelligence?
A: Seemed logical -- I didn't have any real intelligence.
- 12
- Java client-server: what options are there?This is an issue that I have been pondering and investigating
for years, and I wish there was a book, chapter or URL that
covered it.
I have to develop client-server systems in which the following
is pretty much decided:
- The database is Oracle 9iR2
- The server OSs are Solaris and Linux
- The clients (a few dozen) are Windows (XP?)
- The client side runs on Java
Those are the givens, the rest is up for grabs...
The main undecided part is: exactly how to realize the client-server
connection? That's what I would like to hear and read about.
What options do I have?
To get the ball rolling, I will share my experiences so far.
First, I tried the JDBC approach, with a standalone application.
There was a stored procedure in the server, and it was called
from the client. The cons were: the size of the JDBC being much
larger than my app, and there was also the issue of performance.
I feel that I should move more of the functionality and heavy duty
processing to the server side, where I can have plenty of horsepower.
My second attempt was a Java applet which got its data
through CGI-BIN from an OCI C program running on the server.
The performance was pretty good and I'd like to stick with
the OCI part but not with CGI-BIN.
I just began the third approach: using SSH. The server part
is a given since it comes ready in Linux, and I got the Java
client part from sshtools.com.
I have read about servlets, Tomcat, etc. but it looks like once
I get into that stuff (the area seems to be called "Enterprise"),
the tools become extremely expensive (for instance I will have
to upgrade my $700 Developer JBuilder to a $3500 Enterprise JBuilder).
The issue of performance still worries me (I am a speed freak):
I wish I could just use the Unix R-commands (rsh, etc.) so all
the encrypting-decrypting doesn't get in the way of client
performance (my app is Intranet in a trusted environment) but
I guess I can live with the more modern, secure, etc., SSH.
Thanks very much for sharing your expert insight on this,
(and if you are a writer deciding on a topic, I'll bet that
this one will sell a lot of books! - anyone from O'Reilly
out there?)
-Ramon F Herrera
- 13
- gui builder for javaHi,
I just started programming java and I am looking for a free gui builder for
java on linux or windows platforms. Where can I find it.
thanks
Johan
- 14
- DB Selection - J2MEHi,
I am developing an application for PDAs using IBMs
VM (J9). Now my problem is, that I want to store
data on the device. Well, I am using J2ME with
Personal Profile to do this, so file support is
present in this configuration. Now I wonder if
there exist solutions to store data and easily
retrieve it. (commercial, free, open source)
I have to store data on the device, add new
data often, update and delete old data sometimes.
1. So how do you store data, when not having present
a complete RDBMS?
2. There are RDBMS for this platform too.
Any experiences using them?
(for example Pointbase)
3 There is this JDO Option (for example
with ObjectDB) is this working well?
4. What do you think of the following options,
which I already found, but have no idea
whether they will work?
I alread checked:
-JDMB (rather minimalistic, only key/value pairs to be saved)
-JISP (produces rather big files -> not suitable for
constrained devices?)
-HSQL (Anybody got that to work within the mentioned configuration?
I think mainly the java.sql.* classes are missing in the
personal profile)
-ObjectDB (OODB with JDO, no idea exactly if this will
work for my purposes)
Any help will be appreciated
Rene
- 15
- type safety in java 1.5 (bug or hole?)"John C. Bollinger" <email***@***.com> schrieb im Newsbeitrag
news:c8g89n$esu$email***@***.com...
> It would all the same be a nice complement to generics if the 1.5
> compiler would indeed issue warnings about user-inserted casts that are
> not provably correct. (I.e. those that the compiler cannot simply
> ignore). That would give Bracha's comment (that started this confusion)
> broad enough scope to no longer be confusing.
I agree very much.
BTW, there's another comment from Bracha in the very same paper that's
confusing (me): He says "The Java virtual machine does not directly support
overriding of methods with different return types. This feature is supported
by the compiler.". What does this mean? Does this mean that the different
return types are gone at run time? Here's an example:
static class A {
static A create() { return new A(); }
public A m(A a) { System.out.println("A->A"); return a; }
}
static class B extends A {
static B create() { return new B(); }
public B m(A a) { System.out.println("A->B"); return (B) a; }
public B m(B b) { System.out.println("B->B"); return b; }
}
public void testOverriding() {
A a_a = A.create(); // static type A, dynamic type A
A a_b = B.create(); // static type A, dynamic type B
B b_b = B.create(); // static type B, dynamic type B
A a2 = a_a.m(a_b); // prints: A->A
A a3 = a_a.m(b_b); // prints: A->A
A a5 = a_b.m(a_b); // prints: A->B <== overriding works
A a6 = a_b.m(b_b); // prints: A->B <== overriding works
B b2 = b_b.m(a_b); // prints: A->B
B b3 = b_b.m(b_b); // prints: B->B
}
public void testReflection() {
try {
System.out.println(
B.class.getMethod("m", new Class[] {A.class}).getReturnType()
== B.class
); // prints: true <== reflection works, too
}
catch (Throwable t) {
throw new RuntimeException("Laufzeitfehler", t);
}
}
So there's obviously some runtime support for overriding methods with a
different return type, because in this example both the overriding and the
reflection worked. Then what did Bracha mean?
2004-05-24, York.
--
werres at uni minus bremen.de
http://www.uni-bremen.de/~werres
|
|
|