Javaclassnotfound javax.swing.JPanel in a applet
Hi,
I have a applet which use a class which have the code
import javax.swing.JPanel;
public class WebPanel extends JPanel implements Runnable{
Applet parent;
i compile it with jdk1.2.2
my problem is that when i try to run the applet on a Internet Explorer navigator it give me a
javaclassnotfound javax.swing.JPanel
problem.
Javax.swing.JPanel is�nt in IExploter?
Should i put the javax.swing.Jpanel class in the jar fije?
Where i can find it?
Thanks in advance.
forgot to mention this...get the plug in here:
http://java.sun.com/products/plugin/
read the intstructions, u might have to do some 'applet conversion' ....u'll know what I mean when u install the plugin
good luck
Similar Messages
-
Javax.swing.JPanel Help
my application is sort of a game, i planned on having a JPanel subclass called EventPanel have an instance variable _curPanel.
curPanel is of type JPanel. In the constructor I can set curPanel to Other JPanel subclasses. I have another subclass of JPanel called MainScreen, which has the main screen for the game.
I can set curPanel = new MainScreen(); in the constructor for eventPanel. And it works.
But if I try to change _curPanel after i've made it, it wont show up. I have a method which signature
void setPanel(javax.swing.JPanel panel)
_curPanel = panel;
repaint();
}to change the EventPanel, but nothing changes.
In the MainScreen class there is a method call
_eventPanel.setPanel(new NewPlayerPanel());and nothing changes in the code. I have a JTextArea logging info, and in the constructor for NewPlayerPanel at the end it prints a message in my JTextArea. The Panel is being created but not showing up.
I have also tried creating the panel in an instance variable, setting it to setVisbile(true) and trying again and it doesnt work.In other words...
char c=evt.getKeyChar();c is some character based on this event.
if(c=='1'){Ok, let's say it is '1'...
...> char c2=evt.getKeyChar();Then c2 is also '1'.evt.getKeyChar() isn't going to magically change to be something different than it returned when you called it a few lines up before, so...>if(c2=='a')...this can never be true, given the above. -
Accessing javax.swing.JPanel from outside the EDT
Hi everybody!
I am not new to Java but to Swing.
Please consider the following:
public class MyPanel extends JPanel
private int number = 0;
private Object object = null;
public int getNumber()
return number;
public void setNumber(int aNumber)
number = aNumber;
public Object getObject()
return object;
public void setObject(Object aObject)
object = aObject;
Question:
Is it save to call the getters and setters defined above from a Thread other than the Event Dispatching Thread.
From my point of view and my understanding of Swing this should be save as the getters and setters do not touch anything other than the methods and instances defined within the object layer of MyPanel.
Please help :-)jboeing wrote:
I might be wrong, but I think it's safe to touch the non-Swing methods in a subclass from other threads. The main concern in accessing Swing off the EDT is that you can concurrently modify parts of code, but since the EDT does not touch your getters and setters, at least it won't make deadlocks. Perfect, exactly what I would suggest. I couldn't have put it better.
The only oddities may occur if the member variable you set is used in logic for an overriden method (like paintComponent), but I don't think this will be too problematic in most cases.See what you mean so: What about synchronizing the getters and setters. Then only the scheduler would block the EDT as long as another Thread was touching the members. As no wait() and notify() calls arise this should not result in any deadlocks. The worst thing I could think of is that the responsiveness of the user interface may degrade if the EDT had to wait for a while as to many Threads were already waiting for synchronized accesss.
>
Edit:
Oh, and in the future, use the "*Code Formatting Tags*", see http://forum.java.sun.com/help.jspa?sec=formatting
Edited by: jboeing on Nov 13, 2007 1:14 PM
public class Apology{
public static void main(String[] args){
System.out.println("Thank you for your kind advice :-)");
System.out.println("but please don't ask me why this is quoted style");
}Edited by: tog on Nov 14, 2007 6:08 PM -
Javax.swing.KeyStroke
When i use Swing with PJ i get some errors about javax.swing.KeyStroke:
java.lang.NoSuchFieldException
at java.lang.Class.getField()
at javax.swing.KeyStroke.getKeyStroke()
at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults()
at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults()
at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults()
at javax.swing.UIManager.setLookAndFeel()
at javax.swing.UIManager.setLookAndFeel()
at javax.swing.UIManager.initializeDefaultLAF()
at javax.swing.UIManager.initialize()
at javax.swing.UIManager.maybeInitialize()
at javax.swing.UIManager.getUI()
at javax.swing.JPanel.updateUI()
at javax.swing.JPanel.<init>()
at javax.swing.JPanel.<init>()
at javax.swing.JRootPane.createGlassPane()
at javax.swing.JRootPane.<init>()
at javax.swing.JFrame.createRootPane()
at javax.swing.JFrame.frameInit()
at javax.swing.JFrame.<init>()
java.lang.Error: Unrecognized keycode name: VK_KP_LEFT
at javax.swing.KeyStroke.getKeyStroke()
at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults()
at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults()
at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults()
at javax.swing.UIManager.setLookAndFeel()
at javax.swing.UIManager.setLookAndFeel()
at javax.swing.UIManager.initializeDefaultLAF()
at javax.swing.UIManager.initialize()
at javax.swing.UIManager.maybeInitialize()
at javax.swing.UIManager.getUI()
at javax.swing.JPanel.updateUI()
at javax.swing.JPanel.<init>()
at javax.swing.JPanel.<init>()
at javax.swing.JRootPane.createGlassPane()
at javax.swing.JRootPane.<init>()
at javax.swing.JFrame.createRootPane()
at javax.swing.JFrame.frameInit()
at javax.swing.JFrame.<init>()
Could someone help me?Refer to the bug database (bugid = 4309057)
http://developer.java.sun.com/developer/bugParade/bugs/4309057.html
Here the workaround:
Fix the problem yourself by changing SwingUtilites to test for "Class.getPackage" which is 1.2 specific and has not been introduced to pJava:
Method m = Class.class.getMethod("getPackage", null);Re-Jar the swingclasses and enjoy your Swing application running on PersonalJava....
Herbie -
How do I make JPanel focusable in applet?
Consider the following Applet: /* <applet code="MyTest8" width="500" height="300"></applet> */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyTest8 extends JApplet
public void init()
Container contentPane = getContentPane();
contentPane.add(new MyTest8Panel());
class MyTest8Panel extends JPanel implements KeyListener
String s;
public MyTest8Panel()
s="-";
addKeyListener(this);
public void paintComponent(Graphics g)
super.paintComponent(g);
g.drawString(s, 100, 100);
public boolean isFocusable() { return true; }
public void keyTyped(KeyEvent e) { s = s+"-"; repaint(); }
public void keyPressed(KeyEvent e) { }
public void keyReleased(KeyEvent e) { }
} It should add a dash to the screen everytime I hit a key. It doesn't work. It appears the panel never gets focus. What am I doing wrong?Works fine using appletviewer on OS X panther
-
Saving an off screen Swing JPanel to a BufferedImage
First, thanks for reading this. I have read through almost the whole forum and tried countless deviations of examples given here, but to no success.
The situation is that from an Java 1.3 Applet, I am creating the ability for a user to create a simple graphic using standard Swing JTextArea components. This gives him/her the ability to place text arbitrarily on an JPanel. This works fine. The problem comes when the user wants to preview the image with the parametes replaced in the JTextAreas.
We are generating GIF files after the user puts in the data. The problem occurs when we create an off screen JPanel with new JTextAreas with the parameters replaced with the test data filled in. We seem unable to create a BufferedImage from the un-shown JPanel.
I have tried putting the JPanel in a JFrame and showing it before I call paint/print, etc. The only thing that seems to happen is that the JPanel background color is rendered to the GIF file, but not the JTextAreas on the JPanel. I have sucessfully written directly to the Graphics of the JPanel using drawString and generated a GIF, but that does not accomplish our goal.
Any help would be appreciated. A test routine is included to give you the code. TIA.
Kurt
void test() {
int height = 400;
int width = 400;
JFrame jf = new JFrame();
jf.setBounds(0, 0, width, height);
JPanel p = new JPanel();
p.setBackground(Color.blue);
p.setSize(width,height);
JTextArea ta = new JTextArea();
ta.setBackground(Color.black);
ta.setForeground(Color.red);
ta.setText("This is the text to set");
ta.setColumns(10);
ta.setRows(3);
ta.setEditable(true);
ta.setEnabled(true);
ta.setVisible(true);
p.add(ta);
p.validate();
jf.getContentPane().add(p);
jf.validate();
saveToFile(p);
// This was taken and slightly modified for the AnimagedGifEncoder
void saveToFile(JComponent source) {
int w = source.getWidth();
int h = source.getHeight();
int type = BufferedImage.TYPE_INT_RGB;
BufferedImage image = new BufferedImage(w, h, type);
Graphics2D g2 = image.createGraphics();
source.paint(g2);
g2.dispose();
AnimatedGifEncoder gif = new AnimatedGifEncoder();
gif.start("D:/tmp/gifs/mygif.gif");
gif.setDelay(1000);
gif.addFrame(image);
gif.finish();Your approach "putting the JPanel in a JFrame and showing it before I call paint/print" was ok, but it must be done in another thread, this sample is doing a similar job.
You will see that when the print dialog is shown, the frame is fully visible with the button,
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.print.*;
public class PrintF extends JFrame
JPanel pan = new JPanel();
JButton pri = new JButton("Print");
JButton b1 = new JButton("The Click");
public PrintF()
super("This is a full frame print test");
setBounds(1,1,500,350);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent ev)
dispose();
System.exit(0);
getContentPane().add("Center",pan);
pan.setBackground(Color.white);
pan.add(new JLabel("Label 1"));
pan.add(pri);
pri.addActionListener(new ActionListener()
{ public void actionPerformed( ActionEvent e )
TheT t = new TheT(b1);
// printIt();
setVisible(true);
public class TheT extends Thread implements Printable
JFrame frame = new JFrame("The printed frame");
public TheT(JButton b)
frame.setBounds(50,50,400,350);
frame.getContentPane().setLayout(null);
frame.getContentPane().add(b);
b.setBounds(20,80,150,30);
start();
public void run()
frame.setVisible(true);
printIt();
frame.dispose();
private void printIt()
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat pf = pj.defaultPage();
pf.setOrientation(pf.LANDSCAPE);
pj.setPrintable(this,pf);
if (pj.printDialog())
try
pj.print();
catch (Exception e){}
public int print(Graphics g, PageFormat pf, int pi)
throws PrinterException
if (pi > 0)
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
return Printable.NO_SUCH_PAGE;
setCursor(new Cursor(Cursor.WAIT_CURSOR));
g.translate((int)pf.getImageableX()+2,(int)pf.getImageableY()+2);
try
Robot r = new Robot();
Rectangle rect = frame.getBounds();
Image image = r.createScreenCapture(rect);
g.drawImage(image,2,2,null);
catch(AWTException awe)
System.out.println("robot excepton occurred");
return(Printable.PAGE_EXISTS);
public static void main (String[] args)
new PrintF();
} Noah -
I can't use swing components in my applets
When I write an applet without any swing components, my browser never has any trouble finding the classes it needs, whether they're classes I've written or classes that came with Java. However, when I try to use swing components it cannot find them, because it is looking in the wrong place:
On my computer I have a directory called C:\Java, into which I installed my Java Development Kit (so Sun's classes are stored in the default location within that directory, wherever that is), and I store my classes in C:\Java\Files\[path depends on package]. My browser gives an error message along the lines of "Cannot find class JFrame at C:\Java\Files\javax\swing\JFrame.class"; it shouldn't be looking for this non-existent directory, it should find the swing components where it finds, for example, the Applet class and the Graphics class.
Is there any way I can set the classpath on my browser? Are the swing components stored separately from other classes (I'm using the J2SE v1.3)?
Thanks in advance.Without having complete information, it appears that you are running your applets using the browser's VM. Further, I assume you are using either IE or Netscape Navigator pre-v6. In that case, your browser only supports Java 1.1, and Swing was implemented in Java 1.2. You need to use the Java plug-in in order to use the Swing classes (see the Plug-in forum for more information), or else download the Swing classes from Sun and include them in your CLASSPATH.
HTH,
Carl Rapson -
Variable textArea not found in class javax.swing.JFrame...
Making progress on this issue -- but still stuck. Again trying to get the text from a JTextArea on exit:
frame.addWindowListener
(new WindowAdapter() {
public void windowClosing(WindowEvent e)
System.out.println("Why me???" + frame.textArea.getText());
});User MARSIAN helped me understand the scope fo the variables and now that has been fixed. Unfortunately I cannot access my variable textArea in the above code. If get this error:
Error: variable textArea not found in class javax.swing.JFrame
What am I doing wrong?
import java.net.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import FragImpl.*;
public class Framework extends WindowAdapter {
public int numWindows = 0;
private Point lastLocation = null;
private int maxX = 500;
private int maxY = 500;
JFrame frame;
public Framework() {
newFrag();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
maxX = screenSize.width - 50;
maxY = screenSize.height - 50;
makeNewWindow();
public void makeNewWindow() {
frame = new MyFrame(this); //*
numWindows++;
System.out.println("Number of windows: " + numWindows);
if (lastLocation != null) {
//Move the window over and down 40 pixels.
lastLocation.translate(40, 40);
if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) {
lastLocation.setLocation(0, 0);
frame.setLocation(lastLocation);
} else {
lastLocation = frame.getLocation();
System.out.println("Frame location: " + lastLocation);
frame.setVisible(true);
frame.addWindowListener
(new WindowAdapter() {
public void windowClosing(WindowEvent e)
System.out.println("Why me???" + frame.textArea.getText());
//This method must be evoked from the event-dispatching thread.
public void quit(JFrame frame) {
if (quitConfirmed(frame)) {
System.exit(0);
System.out.println("Quit operation not confirmed; staying alive.");
private boolean quitConfirmed(JFrame frame) {
String s1 = "Quit";
String s2 = "Cancel";
Object[] options = {s1, s2};
int n = JOptionPane.showOptionDialog(frame,
"Windows are still open.\nDo you really want to quit?",
"Quit Confirmation",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
s1);
if (n == JOptionPane.YES_OPTION) {
return true;
} else {
return false;
private void newFrag()
Frag frag = new FragImpl();
public static void main(String[] args) {
Framework framework = new Framework();
class MyFrame extends JFrame {
protected Dimension defaultSize = new Dimension(200, 200);
protected Framework framework = null;
private Color color = Color.yellow;
private Container c;
JTextArea textArea;
public MyFrame(Framework controller) {
super("New Frame");
framework = controller;
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setSize(defaultSize);
//Create a text area.
textArea = new JTextArea(
"This is an editable JTextArea " +
"that has been initialized with the setText method. " +
"A text area is a \"plain\" text component, " +
"which means that although it can display text " +
"in any font, all of the text is in the same font."
textArea.setFont(new Font("Serif", Font.ITALIC, 16));
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setBackground ( Color.yellow );
JScrollPane areaScrollPane = new JScrollPane(textArea);
//Create the status area.
JPanel statusPane = new JPanel(new GridLayout(1, 1));
ImageIcon icoOpen = null;
URL url = null;
try
icoOpen = new ImageIcon("post_it0a.gif"); //("doc04d.gif");
catch(Exception ex)
ex.printStackTrace();
System.exit(1);
setIconImage(icoOpen.getImage());
c = getContentPane();
c.setBackground ( Color.yellow );
c.add ( areaScrollPane, BorderLayout.CENTER ) ;
c.add ( statusPane, BorderLayout.SOUTH );
c.repaint ();
}Yeah!!! It works. Turned out to be a combination of DrKlap's and Martisan's suggestions -- had to change var frame's declaration from JFrame to MyFrame:
MyFrame frame;Next, created the external class -- but again changed JFrame references to MyFrame:
public class ShowOnExit extends WindowAdapter {
// JFrame aFrame;
MyFrame aFrame;
public ShowOnExit(MyFrame f) {
aFrame = f;
public void windowClosing(WindowEvent e)
System.out.println("Why me???" + aFrame.textArea.getText()); // aFrame here not frame !!!
}This worked. So looks like even though the original code added a WindowListener to 'frame', the listener didn't couldn't access frame's methods unless it was explicitly passed in as a parameter. Let me know if that's wrong.
Thanks again, all. -
UIManager.look and feel buttons or javax.swing
Hey,
i want to use the ok, cancel etc. button that you get in a JFileChooser or a JOptionPane.
Can they be found in the UIManager or in the javax.swing?
i tried to extract them from the JFileChooser by:
JFileChooser chooser = new JFileChooser("/"); //Linux
JPanel mypanel = new JPanel();
mypanel.add(chooser.getComponentAt(2)); //the button panelthis works, but i don't know how to overwrite the actionlistener to make the buttons listen to my actionlistener.
thanks in advance
Grad_It returns an int value according to what button was clicked
http://72.5.124.55/docs/books/tutorial/uiswing/components/filechooser.html
http://java.sun.com/developer/JDCTechTips/2004/tt0316.html -
Using image as background to Swing JPanel
Hi,
Have been trying to set background of JPanel to an image but cannot get it to work.
Any ideas why not?! Here is the code Ive written:
public Simple_Gui()
//add the title for the frame
super("Simple frame");
this.getContentPane().setLayout(new FlowLayout());
//add a window listener to close the window when the button is pressed
this.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent we)
System.exit(0);
//need a pane to hold the background image and buttons
pane = createPanel();
//this is the background image for the app to make it look lurrrvely
ImageIcon imageIcon = new ImageIcon( "C://SDF_image.jpg" );
//set the size of the Panel to the size of our image
paneHeight = imageIcon.getIconHeight();
paneWidth = imageIcon.getIconWidth();
pane.setSize(paneWidth, paneHeight);
//add the pane to the JFRAME so that it is visible
this.getContentPane().add(BorderLayout.CENTER, pane);
this.setVisible(true);
public static JPanel createPanel()
JPanel panel = new JPanel()
public void paintComponent(Graphics g)
ImageIcon img = new ImageIcon("C://SDF_image.jpg"); Image image = img.getImage();
g.drawImage(image, 0, 0, this); super.paintComponent(g); }
panel.setOpaque(false);
panel.setLayout(new GridLayout(20, 4, 10, 10));
panel.setVisible(true);
return panel;
public static void main(String[] args)
Smarty_Gui gui = new Smarty_Gui();
Sorry about the indentation and formatSomething like this ...
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class UsingImageBackground extends JFrame {
JPanel panel;
JButton button = new JButton("OK!");
public UsingImageBackground() {
Container c = getContentPane();
panel = new JPanel() {
public void paintComponent(Graphics g) {
ImageIcon img = new ImageIcon("new.jpg");
g.drawImage(img.getImage(), 0, 0, null);
super.paintComponent(g);
panel.setOpaque(false);
panel.add(button);
c.add(panel);
public static void main(String [] args){
UsingImageBackground frame = new UsingImageBackground();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(160, 120);
frame.setVisible(true);
} -
JDeveloper 11g javax.swing.GroupLayout
Does JDeveloper 11g support the Swing class javax.swing.GroupLayout ?
I did not see this class in the layout combo, and when I edited in the source code, I got an error:
Field groupLayout not found in class oracle.jdevimpl.uieditor.proxy.JPanel
Thanks a lot.
JohnHi,
its a Java 6 feature and I am afraid to say that we didn't upgrade Swing to Java 6 in this release
Frank -
Set initialName of SWING jPanel on runtime through placeholder
Is it possible to create a jLabel1 on runtime like:
javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
and then set the name jLabel1 from another string or a placeholder.
i would like to set the name from a combination of jLabel and a placeholder such as "CustomerName", so that the name is jLabelCustomerName!
Exact definition:
i have a text file, which contains many customers. if a customer is found then a jLabel should be created. i want to set the name of the jLabel (!! not the text) on runtime, so that the name is jLabelCustomerAlbertEinstein.Ok i will reflect the same example that i am achieving to to.
This is a small extraction of my XPDL file. the participants should be the customers! or in this example these are participants that work on an activity of an BPMN model.
ProcessPackage.xpdl:
<xpdl2:Participants>
<xpdl2:Participant Id="_i3pSAKLFEd60iPJMZdNxfQ" xpdExt:DisplayName="Clerk" Name="Clerk">
<xpdl2:ParticipantType Type="ROLE"/>
<xpdl2:ExtendedAttributes>
<xpdl2:ExtendedAttribute Name="ParticipantSimulationData"><simulation:ParticipantSimulationData SlaMinimumUtilisation="80.0" SlaMaximumUtilisation="95.0">
<simulation:Instances>2</simulation:Instances>
<simulation:TimeUnitCost>
<simulation:Cost>0.21666666666666667</simulation:Cost>
<simulation:TimeDisplayUnit>HOUR</simulation:TimeDisplayUnit>
</simulation:TimeUnitCost>
</simulation:ParticipantSimulationData></xpdl2:ExtendedAttribute>
</xpdl2:ExtendedAttributes>
<iProcessExt:ParticipantProperties UseRoleSemantics="false"/>
</xpdl2:Participant>
<xpdl2:Participant Id="_kUUrYKLFEd60iPJMZdNxfQ" xpdExt:DisplayName="Manager" Name="Manager">
<xpdl2:ParticipantType Type="ROLE"/>
<xpdl2:ExtendedAttributes>
<xpdl2:ExtendedAttribute Name="ParticipantSimulationData"><simulation:ParticipantSimulationData SlaMinimumUtilisation="50.0" SlaMaximumUtilisation="100.0">
<simulation:Instances>1</simulation:Instances>
<simulation:TimeUnitCost>
<simulation:Cost>0.8333333333333334</simulation:Cost>
<simulation:TimeDisplayUnit>HOUR</simulation:TimeDisplayUnit>
</simulation:TimeUnitCost>
</simulation:ParticipantSimulationData></xpdl2:ExtendedAttribute>
</xpdl2:ExtendedAttributes>
<iProcessExt:ParticipantProperties UseRoleSemantics="false"/>
</xpdl2:Participant>
<xpdl2:Participant Id="_lfk9kKLFEd60iPJMZdNxfQ" xpdExt:DisplayName="Operator" Name="Operator">
<xpdl2:ParticipantType Type="ROLE"/>
<xpdl2:ExtendedAttributes>
<xpdl2:ExtendedAttribute Name="ParticipantSimulationData"><simulation:ParticipantSimulationData SlaMinimumUtilisation="85.0" SlaMaximumUtilisation="90.0">
<simulation:Instances>1</simulation:Instances>
<simulation:TimeUnitCost>
<simulation:Cost>0.16666666666666666</simulation:Cost>
<simulation:TimeDisplayUnit>HOUR</simulation:TimeDisplayUnit>
</simulation:TimeUnitCost>
</simulation:ParticipantSimulationData></xpdl2:ExtendedAttribute>
</xpdl2:ExtendedAttributes>
<iProcessExt:ParticipantProperties UseRoleSemantics="false"/>
</xpdl2:Participant>
</xpdl2:Participants>the above example has 3 participants. The Operator, Manager and Clerk which operate an activity of an BPMN model.
readWriteTextFile.java:
// initialization and declaration of important variables such of Classes jPanel, jTabbedPane, jTextField, jLabel....
File aFile = new File(filePath);
// not opening a new BufferredReader which gets aFile (here its the ProcessPackage.xpdl file which is opened by the user through a jFileChooser)
BufferedReader input = new BufferedReader(new FileReader(aFile));
while (( line = input.readLine()) != null){
// this if case checks weather the actual line has the string "<xpdl2:Participants>"
// if it does have this string we can assume that its a Participant-section of the textFile
if(line.indexOf("<xpdl2:Participants>")!= -1){
while(line.indexOf("</xpdl2:Participants>")== -1){
line = input.readLine();
// get the name of the participant which in the above XPDL file is a Manager, Operator or Clerk
participantsNamePosition = line.indexOf("xpdExt:DisplayName=");
if(participantsNamePosition != -1){
participantsName = line.substring(participantsNamePosition);
participantsName = participantsName.substring(participantsName.indexOf("\""), participantsName.indexOf("\" Name="));
// get the number of participants and at it by one! this is to know how many participants we have
numberOfParticipants = numberOfParticipants +1;
// now we got the name of the participant saying if its Manager, Operator or Clerk
// i make it simple because there are several other information extracted from the XPDL-textfile
// now i want to hand over the name of the participant (manager, operator or Clerk) to the class
NewJPanel2_3.setInitialVariablesParticipants(numberOfParticipants, participantsName);
}NewJPanel2_3.java:// HERE COMES THE CODE THAT I'M SEARCHING FOR
// this function is called when the name and the number of Participants are known)
static void setInitialVariablesParticipants(int numberOfParticipants, String participantsName) {
// HERE COMES THE CODE THAT I'M SEARCHING FOR
|
\|/
if(numberOfParticipants == 1){
// it should now create a new jLabel and jTextField and set the text of
// the jTextField of the participants name
// the first participant that is found it the clerk
// manager is found because he is the second found participant
if(numberOfParticipants == 2){
// it should now create a new jLabel and jTextField and set the text of
// the jTextField of the participants name
// the first participant that is found it the clerk
// operator is found because he is the second found participant
if(numberOfParticipants == 3){
// it should now create a new jLabel and jTextField and set the text of
// the jTextField of the participants name
// the third participant that is found it the operator
}additionally i dont want to create 1000 if(numberOfParticipants == 3) steps. that is why i want to set the initial-name (not the text) of the jLabel and JtextField to a participants name, which is in the textBox. -
Unable to set classpath javax/swing/japplet in Linux
Hi,
I have a problem in running an Applet program in Linux. If I run I get the following message.
"Javax/swing/JApplet error Java.lang.NoClassDefFound Error".
I have set my .bash_profile as follows:
CLASSPATH=/usr/java/jdk1.3_0_01/jre/lib
CLASSPATH=/usr/java/jdk1.3_0_01/lib
CLASSPATH=/usr/java/jdk1.3_0_01/
EXPORT
Please tell me whether I have created the .bash_profile correctly. or anything to be changed. It will be great help if anybody hep in this regard. I am held up in my project.
Thnaks.
Mari
11/09/02You don't need to set the CLASSPATH to get javax.swing.JApplet - the JVM "automagically" knows where the rt.jar file is. The only items you need in your CLASSPATH environment are third-party .jar files.
I'm taking a wild guess based on your subject line, but I'll bet you mis-typed the ClassName - "JApplet," not "japplet." Your code should have
import javax.swing.JApplet;in it. -
Problem Loading an Image with javax Swing from a JApplet
First of all, i use JCreator as java creater and have the newest version of java sdk version.
Now i need to load an image from the harddrive on which the JApplet is located. I need to do this from inside the JApplet. I have put my pictures in a map 'images' which is located in the same directory as the classes + htm file. It works from inside JCreator, but as soon as i open the normal htm it just WON'T load that image (grmbl).
Here is my code for loading the image:
public BufferedImage loadImage (String filename, int transparency)
Image image;
if (app)
image = Toolkit.getDefaultToolkit().getImage(("./images/"+filename));
else
String location = "";
location = "./images/"+filename;
image = Toolkit.getDefaultToolkit().getImage(location);
MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(image, 0);
try
mediaTracker.waitForID(0);
catch (Exception e)
Could anybody help me out here??
I tried a url already using getCodeBase() or getDocumentBase() but that gives an error because it cannot find those if using a JApplet.Why don't you use javax.swing.ImageIcon? If you already have a flag telling if it's an application or applet, use the getDocumentBase() to base the URL in the applet part only.
-
Fix for PENDING in javax.swing.text.html.ParagraphView line #131
Investigating source of HTMLEditorKit I found many PENDING things. That's fix for one of them - proper minimal necessary span detecting in table cells.
Hope it will help to somebody else.
import javax.swing.*;
import javax.swing.text.html.*;
import javax.swing.text.html.ParagraphView;
import javax.swing.text.*;
import java.awt.*;
import java.text.*;
import java.util.ArrayList;
public class App extends JFrame {
public static String htmlString="<html>\n" +
"<body>\n" +
"<p>The following table is used to illustrate the PENDING in javax.swing.text.html.ParagraphView line #131 fix.</p>\n" +
"<table cellspacing=\"0\" border=\"1\" width=\"50%\" cellpadding=\"3\">\n" +
"<tr>\n" +
"<td>\n" +
"<p>111111111111111111111111111111111<b>bold</b>22222222222222222222222222222</p>\n" +
"</td>\n" +
"<td>\n" +
"<p>-</p>\n" +
"</td>\n" +
"</tr>\n" +
"</table>\n" +
"<p></p>\n" +
"</body>\n" +
"</html>";
JEditorPane editor=new JEditorPane();
JEditorPane editor2=new JEditorPane();
public static void main(String[] args) {
App app = new App();
app.setVisible(true);
public App() {
super("HTML span fix example");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane split=new JSplitPane(JSplitPane.VERTICAL_SPLIT, createFixedPanel(), createOriginalPanel());
getContentPane().add(split);
setSize(700, 500);
split.setDividerLocation(240);
setLocationRelativeTo(null);
JComponent createOriginalPanel() {
JPanel p=new JPanel(new BorderLayout());
p.add(new JLabel("Original HTMLEditorKit"), BorderLayout.NORTH);
HTMLEditorKit kit=new HTMLEditorKit();
editor2.setEditorKit(kit);
editor2.setContentType("text/html");
editor2.setText(htmlString);
p.add(new JScrollPane(editor2), BorderLayout.CENTER);
return p;
JComponent createFixedPanel() {
JPanel p=new JPanel(new BorderLayout());
p.add(new JLabel("Fixed HTMLEditorKit"), BorderLayout.NORTH);
HTMLEditorKit kit=new MyHTMLEditorKit();
editor.setEditorKit(kit);
editor.setContentType("text/html");
editor.setText(htmlString);
p.add(new JScrollPane(editor), BorderLayout.CENTER);
return p;
class MyHTMLEditorKit extends HTMLEditorKit {
ViewFactory defaultFactory=new MyHTMLFactory();
public ViewFactory getViewFactory() {
return defaultFactory;
class MyHTMLFactory extends HTMLEditorKit.HTMLFactory {
public View create(Element elem) {
View v=super.create(elem);
if (v instanceof ParagraphView) {
v=new MyParagraphView(elem);
return v;
class MyParagraphView extends ParagraphView {
public MyParagraphView(Element elem) {
super(elem);
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
r = super.calculateMinorAxisRequirements(axis, r);
float min=getLongestWordSpan();
r.minimum = Math.max(r.minimum, (int) min);
return r;
public float getLongestWordSpan() {
if (getContainer()!=null && getContainer() instanceof JTextComponent) {
try {
int offs=0;
JTextComponent c=(JTextComponent)getContainer();
Document doc=getDocument();
int start=getStartOffset();
int end=getEndOffset()-1; //don't need the last \n
String text=doc.getText(start, end - start);
if(text.length() > 1) {
BreakIterator words = BreakIterator.getWordInstance(c.getLocale());
words.setText(text);
ArrayList<Integer> wordBounds=new ArrayList<Integer>();
wordBounds.add(offs);
int count=1;
while (offs<text.length() && words.isBoundary(offs)) {
offs=words.next(count);
wordBounds.add(offs);
float max=0;
for (int i=1; i<wordBounds.size(); i++) {
int wStart=wordBounds.get(i-1)+start;
int wEnd=wordBounds.get(i)+start;
float span=getLayoutSpan(wStart,wEnd);
if (span>max) {
max=span;
return max;
} catch (BadLocationException e) {
e.printStackTrace();
return 0;
public float getLayoutSpan(int startOffset, int endOffset) {
float res=0;
try {
Rectangle r=new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);
int startIndex= layoutPool.getViewIndex(startOffset,Position.Bias.Forward);
int endIndex= layoutPool.getViewIndex(endOffset,Position.Bias.Forward);
View startView=layoutPool.getView(startIndex);
View endView=layoutPool.getView(endIndex);
int x1=startView.modelToView(startOffset,r,Position.Bias.Forward).getBounds().x;
int x2=endView.modelToView(endOffset,r,Position.Bias.Forward).getBounds().x;
res=startView.getPreferredSpan(View.X_AXIS)-x1;
for (int i=startIndex+1; i<endIndex; i++) {
res+=layoutPool.getView(i).getPreferredSpan(View.X_AXIS);
res+=x2;
} catch (BadLocationException e) {
e.printStackTrace();
return res;
}Regards,
StasI'm changing the foreground color with
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setForeground(attr, newColor);
int start=MyJTextPane..getSelectionStart();
int end=MyJTextPane.getSelectionEnd();
if (start != end) {
htmlDoc.setCharacterAttributes(start, end, attr, false);
else {
MutableAttributeSet inputAttributes =htmlEditorKit.getInputAttributes();
inputAttributes.addAttributes(attr);
Maybe you are looking for
-
How do I make it the default that when I click on a link it will open in a new tab?
Particularly when I am doing a Google search, but also when I am in a site, I find I frequently have to right click and force 'open in a new tab' to avoid the link overriding the current tab. I want to have all links I click on automatically open in
-
Error message when opening itunes...The itunes library.itl cannot be read because it was created in a newer version of itunes... how do i fix, it will not open with any of my ipod, ipad, iphone.
-
After my PC crashed (MicroSoft blue screen of death), I had to re-format my hard drive, reinstall Windows 7, and ultimately re-install iTunes. I have over 7000 songs on my iPod and want to load them into iTunes, but iTunes tells me my iPod is synced
-
How to add one edge in same page two times?
Please help me for this i want to add same edge two time in page, one edge while onload and another also should load but it will show in popup. thanks in advance.
-
Can't connect to personal domain since iLife upgrade
I would REALLy appreciate any direction here I have a site - www.askkaty2write.com - which I give clients to see my writing samples. I upgraded it iLife09 yesterday and now cannot connect to my personal domain. I get the "Looking for something on Mob