Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > why my applet can't display components like JButton or JTextField, but JLabel is well

Reply
Thread Tools

why my applet can't display components like JButton or JTextField, but JLabel is well

 
 
feofao@gmail.com
Guest
Posts: n/a
 
      12-23-2005
why my applet can't display components like JButton or JTextField, but
JLabel is well

 
Reply With Quote
 
 
 
 
zero
Guest
Posts: n/a
 
      12-23-2005
wrote in news:1135317413.624665.16940
@g44g2000cwa.googlegroups.com:

> why my applet can't display components like JButton or JTextField, but
> JLabel is well
>
>


Because your computer has a pixie inside the cd-rom drive which eats
JButtons. The JTextFields are just afraid of being eaten too, even though
the pixie doesn't like them.

Without code, we can't help you.

--
Beware the False Authority Syndrome
 
Reply With Quote
 
 
 
 
ripleyfu@gmail.com
Guest
Posts: n/a
 
      12-24-2005
sorry, my code is:

// FileChooserPanel.java
package test.applets;


import java.io.File;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JFileChooser;
import javax.swing.filechooser.*;


//import javax.swing.JLabel;


public class FileChooserPanel extends JPanel
implements ActionListener {
JTextField uploadpath;
JButton opendirButton;
JFileChooser fc;


public FileChooserPanel() {
fc = new JFileChooser();
uploadpath = new JTextField(20);
JPanel uploadpathPanel = new JPanel();
uploadpathPanel.add(uploadpath);


opendirButton = new JButton("Open File...");
opendirButton.addActionListener(this);
JPanel buttonPanel = new JPanel();
buttonPanel.add(opendirButton);


add(uploadpathPanel);
add(buttonPanel);


// this will be ok
//JLabel lab = new JLabel("Hello, World!");
//add(lab);


}


public void actionPerformed(ActionEvent e) {
if (e.getSource() == opendirButton) {
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_O NLY);
int returnVal = fc.showOpenDialog(FileChooserPanel.this);


if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
uploadpath.setText(file.toString());
}
else {
uploadpath.setText("");
}
}
}



}


// FileChooserApplet.java
package test.applets;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.UIManager;


import test.applets.FileChooserPanel;


public class FileChooserApplet extends JApplet {
private void createGUI() {
FileChooserPanel fcp = new FileChooserPanel();
fcp.setOpaque(true);
fcp.setBackground(Color.white);
setContentPane(fcp);
}


public void init() {
try {

UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
}
catch (Exception e) {
System.err.println("createGUI didn't successfully
complete");
}
}



}

 
Reply With Quote
 
Paulus de Boska
Guest
Posts: n/a
 
      12-24-2005
Well, it ran fine, when I tried it under 1.4.2_10, but some comments:
you don't need javax.swing.SwingUtilities.invokeAndWait in init.
There's no painting until well after init has finished, so doing GUI
stuff in init is safe. You only need that in some special cases, as I
explain here (if your browser supports the use of applets) :
http://javalessons.com/cgi-bin/ui/ja...=ths&sid=ao789
Another thing, why not add the components to FileChooserPanel straight
away, instead of putting them in other panels first ?
Hope this helps,

---
Paul Hamaker, SEMM
http://javalessons.com

 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      12-24-2005
Paulus de Boska wrote:
> Well, it ran fine, when I tried it under 1.4.2_10, but some comments:
> you don't need javax.swing.SwingUtilities.invokeAndWait in init.
> There's no painting until well after init has finished, so doing GUI
> stuff in init is safe. You only need that in some special cases, as I


Sun's information on this is contradictory. In fact, you do need the
invokeAndWait to be safe, as Swing (particularly text) is booby-trapped
with invokeLaters.

> explain here (if your browser supports the use of applets) :
> http://javalessons.com/cgi-bin/ui/ja...=ths&sid=ao789


Or use appletviewer from the JDK.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-26-2005
wrote:
> why my applet can't display components like JButton or JTextField, but
> JLabel is well


What Java is your browser running?
<http://www.physci.org/pc/property.jsp?prop=java.version+java.vendor>

What is the exception showing in the Java Console?

--
Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JButton or JLabel? pek Java 0 06-17-2008 11:54 PM
vertical BoxLayout, JLabel, and JButton and alignment Duane Evenson Java 5 09-27-2007 07:33 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Can Choice components respond to keyboard input like HTML Choice components? Mickey Segal Java 0 02-02-2004 10:59 PM
How to display the texts into 2 line in JButton? James Java 2 11-11-2003 10:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57