How to display text file in swing
hello,
I have screen where user enters batch number and number.
when key is pressed a list is displayed on the screen.how to do this and how to relate my actionlistener with the function that generates the list...
Hi,
It is simple. Just create a button and add it to the action listener as button.addActionListener(this);
Your class should extend ActionListener. and also there should be a method named - actionPerformed(ActionEvent avt) in your class
Now inside this method, just compare the action as:
if(avt.getSource()==button)
// in this method, hjust take your file contents and display it on the same window, or create a new Frame here and display it in that window.
If you want to display the file contents in the same window, then do the following.
Declare a public JLabel variable for the class and create the JLabel along with the other components as usual but without giving any values. Now in the action part of the button, read the file contents in a string variable, and set the string to the jlabel as folows:
label.setText(string);
Hope it helps,
Cochu.
Similar Messages
-
How to display text file in JSP?
Hi,
I am new to servlet/JSP/java programming.
I have been able to download a file using ftp. I dont know who to display it in JSP.
Here is my code. Any help will be appreciated...
<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<%@ page import="com.dmhistory.*" %>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<%
byte[] bytes = new byte[4096];
URL theUrl = new URL("ftp://user:passwd@host/migr/Movers_for_Ora8/BG/logs/FLD-PAC3-20020311.log");
BufferedInputStream in = new BufferedInputStream(theUrl.openStream());
BufferedOutputStream outstream = new BufferedOutputStream(new FileOutputStream( new File( "D:/temp/log.txt" )));
int pos = in.read( bytes );
while ( pos != -1) {
outstream.write( bytes, 0, pos );
pos = in.read( bytes );
%>
<%
in.close();
%>
DONE!!!
</body>
</html>
How can i display this downloaded file in the browser?
I want to display it in the original format i.e which new line and carriage returns...line by line..
Thanks,Hi,
I finally go it to display. but now I have new problem. The browser shows the text without the /n/r.
But when I view the source using 'view->source', if see that the text has got proper format with newline and carriage returns.
Any ideas how to display it correctly in the browser?
<%
URL theUrl = new URL("ftp://user:pwd@host/migr/Movers_for_Ora8/BG/logs/FLD-PAC3-20020311.log");
//URL theUrl = new URL("ftp://dbcmaint:[email protected]/migr/Movers_for_Ora8/SNP/logs/SNP-PAC2-20020314.log");
URLConnection uc = theUrl.openConnection();
InputStream content = uc.getInputStream();
BufferedInputStream in = new BufferedInputStream (content);
LineNumberReader lnr = new LineNumberReader (new InputStreamReader (in));
String tempStr = "";
String str = "";
while ((tempStr = lnr.readLine()) != null) {
str += (tempStr);
%>
<%=tempStr%>
<%tempStr = "";
%>
<%
in.close();
lnr.close();
%>
Thanks -
How to display text file text in aTextArea component
Hello
ive managed to display the text file text in the console, but i want it to show up in the textArea component i have in a frame,
it seems to display the last character . in the text area
wheres the rest of the text...this was a lot easier in VB.NET
any help would be much appreciated
heres my code...
private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed
// TODO add your handling code here:
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files Only","txt");
editorFileChooser.setFileFilter(filter);
int returnVal = editorFileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION){
System.out.println("You chose to open this file: " + editorFileChooser.getSelectedFile().getName());
openFileName = editorFileChooser.getSelectedFile().getName();
openFile = new File(openFileName);
try {
this.readFile = new FileReader(openFile);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
int inputCharacters;
try {
while ((inputCharacters = readFile.read()) != -1){
System.out.print((char)inputCharacters);
char[]CHARAARAY = {(char)inputCharacters};
s3 = new String(CHARAARAY );
this.editorTextArea.setLineWrap(true);
this.editorTextArea.setText(s3.toString());
readFile.close();
catch(IOException ex){
System.out.println();
}//GEN-LAST:event_openButtonActionPerformed>
wheres the rest of the text...this was a lot easier in VB.NET>If you only need to code for Windows, use VB. For code that works on computers, learn the Java idioms, especially with regard to X-plat issues with Files.
>
heres my code...>That was a code snippet. You will get better chance of help around these parts, if you can prepare an SSCCE. The code below* is an SSCCE.
There was a basic problem in the logic of that code, that resulted in the assumption (by the JRE) that every file the user attempted to load, was located in the 'current directory'. It was fixed by abandoning the String based file name of the file, and instead setting openFile to the selected file in the chooser. I also demolished the loading code by replacing the JTextArea with a JEditorPane (much easier).
* Altered code;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.io.*;
class TestLoadFile extends JPanel {
JFileChooser editorFileChooser;
File openFile;
JEditorPane editorTextArea;
TestLoadFile() {
super(new BorderLayout());
editorTextArea = new JEditorPane();
add(
new JScrollPane(editorTextArea),
BorderLayout.CENTER );
JButton load = new JButton("Load File");
load.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent ae) {
openButtonActionPerformed(ae);
add( load, BorderLayout.SOUTH );
editorFileChooser = new JFileChooser();
public static void main(String[] args) {
TestLoadFile tlf = new TestLoadFile();
JOptionPane.showMessageDialog(null, tlf);
Dimension preferredSize = new Dimension(600,400);
public Dimension getPreferredSize() {
return preferredSize;
private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_openButtonActionPerformed
// TODO add your handling code here:
FileNameExtensionFilter filter = new
FileNameExtensionFilter("Text Files Only","txt");
editorFileChooser.setFileFilter(filter);
int returnVal = editorFileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION){
System.out.println("You chose to open this file: " +
editorFileChooser.getSelectedFile().getName());
// wrong!
//openFileName = editorFileChooser.getSelectedFile().getName();
//openFile = new File(openFileName);
// right!
openFile = editorFileChooser.getSelectedFile();
try {
editorTextArea.setPage(openFile.toURI().toURL());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//GEN-LAST:event_openButtonActionPerfor
} -
How to display XML file in java swing
hi all
now i do my M.Sc., project on data maining.this time i have one problem,thats i can't display XML file in swing frame.so any one know this plz give me that idea or code.
Thanks to all.
RSKOne way of doing that is to use JDOM...
u create an xml tree, and then output using XMLOutputter class...it will be displayed in text...im not sure if thats what u want...however, if u do want to represent it visually then u may need to draw a tree...u may use the Graphics2D for that...there are alot of ways to do such thing, and the 2 possibilities arent the best...depends on what u want...elaborate more pls. -
How to display Pdf file in iPad site
Hi
How to display Pdf file in web page which can able to view in iPad safari?
Thanks,
ArunYou can't really.
You need to use DHTML in the swf-wrapper HTML file, usually a
division wrapped iFrame, and load the PDF into the iFrame as an
overlay to the Flash. -
How to display text on last but one page in SAPSCRIPTS
how to display text on last but one page in SAPSCRIPTS
u have create one Foooter window , this has to be called in only One Page.So hardcode /assign this window to only one PAGE number.
regards
Prabhu -
How to display Doc file format in the JEditPane?
At this time , JEditPane supports RTF and HTML file format ,but
Could anyone tell me how to display DOC file format using JEditPane
or other JTextComponents?
Thx a lot!
CatonHi,
there is no support for doc files (M$ Word?) in Java. You would have to create your own classes for that eventually subclassing JEditorPane, EditorKit, Document etc. As well you'd need your own reader for the doc format.
The problem I see with that however is that there is nothing such as thedoc file format. Microsoft just saves anything produced by MS Word into files ending with .doc. But, if there is anything such as a .doc file format, it changes more often than the weather in April.
Ulrich -
How to display the file status in the status bar?
Hi all,
Can anyone tell me how to display the file status in the status bar?
The file status can consists: the type of the file, the size of the file etc..
thanx alot..class StatusBar extends JComponent {
JLabel l = new JLabel("ready");
public StatusBar() {
super();
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
add(l);
public void setText( String prompt ) {
l.setText(prompt);
setVisible( true );
public void paint(Graphics g) {
super.paint(g);
} -
How to display texts automatic. besides entered value for a field in Trans.
How to display texts automatically besides the entered value for a field in a standard transaction screen. For example you have a value table and a text table associated to it. Then on entering the value field and pressing enter the text associated should get displayed immediately besides the value. Like if you have 'LOC' as the value and 'Location' as the text associated to it, on entering this value 'LOC', you automatically get the text 'Location' printed besides it automatically in a transaction screen ?
Message was edited by: Sarika KediaHi sarika,
Welcome to SDN.
1. first of all, such display of text,
is not automatic.
(it appears to be automatic)
2. At design time,
a) take one extra field for text
and mark it as OUTPUT ONLY
3. Then in PBO coding,
call some module, and in that module
write code
4. The code should be to
select from TEXT Table
into the work area.
EG. THE SCREEN TEXT FIELD NAME IS
T510A-FIELDNAME.
CLEAR t510a.
SELECT SINGLE * FROM t510a INTO t510a
WHERE trfar = FIELVALUE.
5. This will take care of
displaying the text value of that field.
regards,
amit m. -
How to display flash file in adf pages
how to display flash file in adf pages need help
Thanks all,
It is resolved.
the code i am using to display a flash is below.
<f:verbatim>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version
=10,0,0,0" width="300" height="300" id="11gR1_aniH_grey" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="wmode" value="transparent" />
<param name="movie" value="mx2004demo.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#4d5c64" />
<embed src="../Images/mx2004demo.swf" quality="high" width="300" height="300" name="mx2004demo.swf" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false"
type="application/x-shockwave-flash" wmode="transparent"
pluginspage="http://www.adobe.com/go/getflashplayer" />
</object>
</f:verbatim> -
How to write text file in Shockwave?
Does anybody know how to write text file in Shockwave to
user's disk?
Thanks in advance.Those Xtras can wreak to much havoc when used with the wrong
intent.
What you can do is write with setpref and store a list of
saves and the
saves itself seperatly. Then you'd have to build your own
save/open
dialog to let the user:
* pick a previously saved file to load or overwrite
* have the user type the name of a new file to save.
Only thing that remains is that the user cannot decide where
the files
are saved.
Manno
SiuLinda wrote:
> Thanks a lot for your reply.
> Yes, cookies is good but I have to write a program to
save the text file in
> where the user wants, user can open these files later if
they like, like using
> Filextra and Fileio, but I found all of these xtras seem
to be not supported in
> shockwave.
>
Manno Bult
[email protected] -
How to display XSL file to ASPX in dreamweaver
Hi,
Just wondering how to display XSL file in ASPX page?
I normally do it in ASP page by using server behaviour XSLT transformation and bind it to ASP page and this works very well.
Now I am trying to use the same method and using ASPX page this time but this time there is no option from server behaviour where I can bind it to my ASPX.
Can someone help or perhaps let me know where I can find the information how to do it?
Thanks,
Rush OYou mean you want to see the XML source?
You need to replace the characters '<' and '&' with corresponding entities '<' and '&'. You can use replaceAll, but do the ampersands first.
Then I suggest you probably want to put them in a <PRE> block. -
How to read text file line by line...?
how to read text file line by line, but the linefeed is defined by user, return list of string, each line of file is a item of list?
please help me.
Thanks very muchBrynjar wrote:
In Groovy, you would do something like:
linefeed = "\n" //or "\r\n" if the user chose so
lines = new File('pathtofile').text.split("${linefeed}")This is one of the things that has always annoyed me about Sun's sdk, i.e. the lack of easy ways to do things like that. You always end up making your own utilities or use something like Apache's commons.io. Same goes for jdbc and xml - I'll wait for appropriate topics to show how easy that is in Groovy :)I generally agree, but what I really don't like about the Groovy text-file handling niceties: They don't care about encoding/always use the default encoding. And as soon as you want to specify the encoding, it gets a lot more complex (granted, it's still easier than in Java). -
How to display RTF file and .doc file in JTextPane
How to display RTF file and .doc file in JTextPane??
Duplicate post
http://forum.java.sun.com/thread.jsp?forum=57&thread=567029&tstart=0&trange=30 -
How to display text on last but one page
how to display text on last but one page
Hi Preeti,
If u r working on a smartform then click on th window go to the condition tab there
at the end u will find events click on the the event on which u want to trigger the
print.
If u r working on a script then create a text element and call this text elemtn at
the end of processing of the main window, this will make sure that thetext element
is triggered only at the end.
I hope that helps u , if not pls let me know.
Regards,
Vaibhav B Gawali.
Maybe you are looking for
-
ALV Output Screen ..........
Hi Experts, In ALV report for FM we use PF_STATUS_SET. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_pf_status_set = 'PF_STATUS_SET' For each time we have to go in se41 and copy the standard screen full screen for : FORM pf
-
TYPELOAD_NEW_VERSION in SAP CRM 7.0
Hi, Whenever we try to execute any workbench transaction like SE38 or SE37 and view any source code, we get the following runtime error: Runtime Errors TYPELOAD_NEW_VERSION Date and Time 09/10/2010 09:25:25 Short text A newer ve
-
A question about ShellCreation in 4.0
Friends: I did tons of ShellCreation in version3.0. Now I review the document for TDMS4.0. I notice there is an issue about the export which is described in the attached. Thanks for your input.
-
Hi, idoc sender adpter lies on integration engine,,:thats y it dnt need an sender agreement and sender comm' chanell"then 1> why does a "receiver adapter needs comm channel and rec agrrement". 2>does it lie on integraton engine or not? please le
-
My iphone 4 camera shutter won't open. I have already done a restore and I am using the latest iOS. The front facing camera works during FaceTime but crashes when I switch to rear camera. in Camera mode I can't switch to front camera. I plan on repla