Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Community > Tech > [JAVA] Swing, problema
Pages (2): [1] 2 »   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
PuDDu
.mechanist.

User info:
Registered: Sep 2002
Posts: 183 (0.02 al dì)
Location: Dunwich, MA
Corso: Comunicazione Digitale
Anno: 0x03
Time Online: 3 Days, 18:49:12 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Unhappy [JAVA] Swing, problema

Salve, volevo sapere se qualcuno si è destreggiato con la API grafica di Java, Swing.

So che nel corso di java non è mai stato affrontato (purtroppo) ma io mi sto dilettando ad imparare un po' di programmazione in java con interfaccia grafica, appunto con Swing.

Il mio problema è questo:

sto creando un piccolo e semplice editor testuale, che ricalchi le funzioni di notepad, ma scritto in Java.
Per farlo uso un po' di compenenti di Swing, come le JMenuBar e le JTextComponent (JTextArea, JEditorPane) ma non funzionano alcune cose.

Se uso una JTextArea per visualizzare il testo, posso fare diverse cose carine, come formattarlo per farlo andare a capo alla fine della finestra (come la funzione "a capo automatico" di Notepad, per intenderci) ma siccome JTextArea "manipola" solo stringhe, l'unico modo per aprire file di testo con il mio programmino è quello di "appendere" le stringhe con un filestream una dietro l'altra e printarle sulla TextArea, con lo spiacevole effetto che una volta aperto un testo la barretta lampeggiante dell'inserimento carattere -> | (non mi ricordo come si chiama, spero capiate a cosa mi riferisco :D) si trova IN FONDO al documento e quindi il documento stesso e visualizzato nella finestra dal fondo.

Ho provato ad usare allora JEditorPane, component che permette di visualizzare oltre a plaintext anche HTML e RTF e che manipola sia string che "page" e che una volta aperto un file lo visualizza come si deve, ma non ha le funzioni di a capo automatico, cosa alquanto sgradevole.

La mia domanda è questa: qualcuno sa come potrei fare tornare la barretta a inizio documento ed evitare di "appendere" le stringhe una dietro l'altra per aprire un file con JTextArea?
Oppure mettere l'a capo automatico a JEditorPane?

Grazie, se volete vi mando anche i sorgenti per spiegarvi in dettaglio.

Ciao

__________________
ÞµÐе
Fatti non foste a viver come bruti ma per seguir virtute e canoscenza
]=-----=[ ¿ Need Contact ? ]=------=[
]=-----=[ ~ ICQ ‡‡ E-mail ~ ]=------=[
]=-----=[ ¥ My DeviantArt ¥ ]=------=[

08-05-2003 20:40
Click Here to See the Profile for PuDDu Click here to Send PuDDu a Private Message Visit PuDDu's homepage! Find more posts by PuDDu Add PuDDu to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
aesse
args[]

User info:
Registered: Dec 2002
Posts: 50 (0.01 al dì)
Location: Milano
Corso: TICO
Anno: 1
Time Online: 1 Day, 19:15:38 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

usando JTextarea puoi sia appendere stringhe alla textarea, sia leggere tutto il tuo file, memorizzarlo in una stringa, e aggiungere la stringona alla textarea (dovrebbe esserci un setText() derivato da TextComponent o qualcosa del genere).
Per spostare il cursore secondo me potresti tentare di giocare con (vado a memoria quindi controlla sulla documentazione) con setSelectionStart() e setSelectionEnd(), oppure usando la classe Caret (setCaretPosition() ).
p.s. prendi tutto ciò che dico con le pinze..fino a qualche mese fa non sapevo neanche cosa fosse la programmazione ad oggetti!

08-05-2003 23:10
Click Here to See the Profile for aesse Click here to Send aesse a Private Message Visit aesse's homepage! Find more posts by aesse Add aesse to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
PuDDu
.mechanist.

User info:
Registered: Sep 2002
Posts: 183 (0.02 al dì)
Location: Dunwich, MA
Corso: Comunicazione Digitale
Anno: 0x03
Time Online: 3 Days, 18:49:12 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Grazie mille! Ho risolto usando setCaretPosition.

Ora però ho un altro dubbio:
c'è un modo di "cancellare" (repaint sarebbe più adatto) una JTextArea?
Ovvero, quando apro un nuovo file il mio algoritmo "riappende" il testo a quello già presente nella finestra.

So che ci deve essere, ma non so dove.

__________________
ÞµÐе
Fatti non foste a viver come bruti ma per seguir virtute e canoscenza
]=-----=[ ¿ Need Contact ? ]=------=[
]=-----=[ ~ ICQ ‡‡ E-mail ~ ]=------=[
]=-----=[ ¥ My DeviantArt ¥ ]=------=[

09-05-2003 09:43
Click Here to See the Profile for PuDDu Click here to Send PuDDu a Private Message Visit PuDDu's homepage! Find more posts by PuDDu Add PuDDu to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
0m4r
.grande:maestro.

User info:
Registered: Mar 2002
Posts: 7287 (0.84 al dì)
Location: Düsseldorf (DE)
Corso:
Anno: ESAMI FINITI
Time Online: 49 Days, 0:57:33 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

puoi fare

code:
jta.setText(""); jta.setText("asasdfkj uyhg uhfkh gfkudhgku sdhdhf ");

cioè, prima la svuoti e poi ci piazzi il testo nuovo...non è molto elegante ma funziona. (Spero di avere capito qual è il problema)

P.S.
link utili:
http://forum.java.sun.com
http://java.sun.com/docs/books/tuto...iswing/TOC.html

__________________
http://www.twitter.com/0m4r

09-05-2003 10:02
Click Here to See the Profile for 0m4r Click Here to See the Blog of 0m4r Click here to Send 0m4r a Private Message Find more posts by 0m4r Add 0m4r to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
0m4r
.grande:maestro.

User info:
Registered: Mar 2002
Posts: 7287 (0.84 al dì)
Location: Düsseldorf (DE)
Corso:
Anno: ESAMI FINITI
Time Online: 49 Days, 0:57:33 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Off-Topic:

visto che usate swing non è che mi dareste una mano qui: http://www.dsy.it/forum/showthread.php?s=&threadid=3870

__________________
http://www.twitter.com/0m4r

09-05-2003 10:03
Click Here to See the Profile for 0m4r Click Here to See the Blog of 0m4r Click here to Send 0m4r a Private Message Find more posts by 0m4r Add 0m4r to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
PuDDu
.mechanist.

User info:
Registered: Sep 2002
Posts: 183 (0.02 al dì)
Location: Dunwich, MA
Corso: Comunicazione Digitale
Anno: 0x03
Time Online: 3 Days, 18:49:12 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Grazie Omar, ora funza tutto!

Anche io appena avrò finito di implementare l'apertura-salvataggio dei documenti e altre cosette, mi dovrò smazzare il printing, ma per ora so poco o nulla.

__________________
ÞµÐе
Fatti non foste a viver come bruti ma per seguir virtute e canoscenza
]=-----=[ ¿ Need Contact ? ]=------=[
]=-----=[ ~ ICQ ‡‡ E-mail ~ ]=------=[
]=-----=[ ¥ My DeviantArt ¥ ]=------=[

09-05-2003 10:09
Click Here to See the Profile for PuDDu Click here to Send PuDDu a Private Message Visit PuDDu's homepage! Find more posts by PuDDu Add PuDDu to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
morf
e.Vanishing guy

User info:
Registered: Nov 2002
Posts: 1856 (0.22 al dì)
Location: Treviglio (BG)
Corso: TICO
Anno: primo
Time Online: 5 Days, 11:35:09: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

... mi sento tanto ignorante ...

__________________
mail, msn and steam account: morf@email.it
my blog: http://melien.blogspot.com
my shots: http://mr-anf.deviantart.com


" ... fear is how I fall ... "

09-05-2003 10:38
Click Here to See the Profile for morf Click here to Send morf a Private Message Visit morf's homepage! Find more posts by morf Add morf to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
PuDDu
.mechanist.

User info:
Registered: Sep 2002
Posts: 183 (0.02 al dì)
Location: Dunwich, MA
Corso: Comunicazione Digitale
Anno: 0x03
Time Online: 3 Days, 18:49:12 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

JAVA :rulez:

Morf :asd:

__________________
ÞµÐе
Fatti non foste a viver come bruti ma per seguir virtute e canoscenza
]=-----=[ ¿ Need Contact ? ]=------=[
]=-----=[ ~ ICQ ‡‡ E-mail ~ ]=------=[
]=-----=[ ¥ My DeviantArt ¥ ]=------=[

09-05-2003 10:39
Click Here to See the Profile for PuDDu Click here to Send PuDDu a Private Message Visit PuDDu's homepage! Find more posts by PuDDu Add PuDDu to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
morf
e.Vanishing guy

User info:
Registered: Nov 2002
Posts: 1856 (0.22 al dì)
Location: Treviglio (BG)
Corso: TICO
Anno: primo
Time Online: 5 Days, 11:35:09: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Off-Topic:
io in verità java l'ho fatto un po' per l'esame di Informatica Generale del primo semestre ... ma leggere tutto questo mi fa capire che ho fatto davvero il minimo :roll:

__________________
mail, msn and steam account: morf@email.it
my blog: http://melien.blogspot.com
my shots: http://mr-anf.deviantart.com


" ... fear is how I fall ... "

09-05-2003 10:42
Click Here to See the Profile for morf Click here to Send morf a Private Message Visit morf's homepage! Find more posts by morf Add morf to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Quartermaster
=]3BOL4[=

User info:
Registered: Nov 2002
Posts: 628 (0.07 al dì)
Location: Baronx -Mi
Corso: corsi..
Anno: DoK
Time Online: 9 Days, 9:27:52 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

:? saimo in due morf...:cry:

09-05-2003 14:06
Click Here to See the Profile for Quartermaster Click here to Send Quartermaster a Private Message Find more posts by Quartermaster Add Quartermaster to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ToBlEr:OnE
.arcimaestro.

User info:
Registered: Apr 2003
Posts: 264 (0.03 al dì)
Location: Cusano M. (MI)
Corso: Comunicatio Digitalis
Anno: TRE(sh)
Time Online: 1 Day, 23:07:14 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Morf, hai passato l'esame con un over 20. La cosa ti procura solo stima ed invidia.
Vai in pace...

__________________
Blow[mono/CASUAL]*lab®

http://www.tobler.tk

10-05-2003 18:05
Click Here to See the Profile for ToBlEr:OnE Click here to Send ToBlEr:OnE a Private Message Visit ToBlEr:OnE's homepage! Find more posts by ToBlEr:OnE Add ToBlEr:OnE to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
webnoise
:-. just me .-:

User info:
Registered: Nov 2001
Posts: 670 (0.08 al dì)
Location:
Corso:
Anno:
Time Online: 12 Days, 6:41:08: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

anche perche' il cammino e' lungo.... l'anno prox vedrai che belle sorprese :D

__________________
Per una vita senza tabacco

24-05-2003 15:56
Click Here to See the Profile for webnoise Click Here to See the Blog of webnoise Click here to Send webnoise a Private Message Find more posts by webnoise Add webnoise to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Rifinitore
.illuminato.

User info:
Registered: Nov 2002
Posts: 189 (0.02 al dì)
Location: Pesaro/Milano
Corso: Laureato
Anno:
Time Online: 2 Days, 17:52:28 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

che tipo di sorprese ?

__________________
Peppe
http://www.peppedotnet.it

24-05-2003 19:11
Click Here to See the Profile for Rifinitore Click here to Send Rifinitore a Private Message Find more posts by Rifinitore Add Rifinitore to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
0m4r
.grande:maestro.

User info:
Registered: Mar 2002
Posts: 7287 (0.84 al dì)
Location: Düsseldorf (DE)
Corso:
Anno: ESAMI FINITI
Time Online: 49 Days, 0:57:33 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

già, che sorprese?

__________________
http://www.twitter.com/0m4r

25-05-2003 11:30
Click Here to See the Profile for 0m4r Click Here to See the Blog of 0m4r Click here to Send 0m4r a Private Message Find more posts by 0m4r Add 0m4r to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
webnoise
:-. just me .-:

User info:
Registered: Nov 2001
Posts: 670 (0.08 al dì)
Location:
Corso:
Anno:
Time Online: 12 Days, 6:41:08: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

che il secondo anno e' molto impegnativo IN TUTTI I SENSI... a buon intenditor poche parole.... :evil: :)

__________________
Per una vita senza tabacco

25-05-2003 14:11
Click Here to See the Profile for webnoise Click Here to See the Blog of webnoise Click here to Send webnoise a Private Message Find more posts by webnoise Add webnoise to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 22:47.    Post New Thread    Post A Reply
Pages (2): [1] 2 »   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.086 seconds (58.40% PHP - 41.60% MySQL) con 25 query.