Grande amigo Ricardo, obrigado pelo pronto atendimento.
Segue o código completo conforme vc pediu e no final, um click no botão Texto pré-formatado
package Formularios;
import Classes.Sonumeros;
import static Formularios.FrmVisMusicas.txtpmusica;
import java.awt.Color;
import java.awt.Image;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
class Cifra {
final int numeroDaLinha;
final String name;
final int inicio;
final int fim;
Cifra(String name, int inicio, int fim, int numeroDaLinha) {
this.name = name;
this.inicio = inicio;
this.fim = fim;
this.numeroDaLinha = numeroDaLinha;
}
}
public class FrmMusicaPlay extends javax.swing.JInternalFrame {
String caminhoDasMusicas = "C:\\MUSIC PLAY\\MusicasTeclado\\";
String caminhoDasNotas = "C://MUSIC PLAY//NotasTeclado//";
String flag;
int cont =800;
int totalLin=0;
boolean clicado;
Pattern p = Pattern.compile("[ABCDEFGabcdefgMm()0123456789/_dim#b°º+]+");
List<Cifra> cifras = new ArrayList<>();
static int current = 0;
Cifra c;
private Object e;
public FrmMusicaPlay() {
initComponents();
final JTextField ftf = txttempo; // coloca um setfocus no JTextField (txttempo)
javax.swing.SwingUtilities.invokeLater(ftf::requestFocusInWindow);
txttempo.setDocument(new Sonumeros());
try {
List<String> lines = new ArrayList<>();
BufferedReader ler = new BufferedReader(new InputStreamReader(
new FileInputStream(caminhoDasMusicas + txtpmusica.getText() + ".txt"), "UTF-8"));
String lin = ler.readLine();
int offset = 0;
int line = 0;
int i = 0;
while (lin != null) {
lines.add(lin);
if (line % 2 == 0) {
Matcher m = p.matcher(lin);
while (m.find()) {
cifras.add(new Cifra(m.group(), m.start() + offset, m.end() + offset , line));
}
}
offset += lin.length() + 1;
i++;
line++;
lin = ler.readLine();
totalLin ++;
}
txtareamus.setText(String.join("\n", lines));
} catch (Exception e) {
System.out.println("erroo na leitura: " + e.getMessage());
}
txtareamus.setCaretPosition(0);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
Btnsair = new javax.swing.JButton();
btniniciar = new javax.swing.JButton();
lblnota = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtposicao = new javax.swing.JTextField();
txttempo = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
txtareamus = new javax.swing.JTextPane();
Btnsair.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
Btnsair.setForeground(java.awt.Color.red);
Btnsair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/Sai_Peq.png"))); // NOI18N
Btnsair.setText("Sair");
Btnsair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnsairActionPerformed(evt);
}
});
btniniciar.setFont(new java.awt.Font("Arial", 1, 22)); // NOI18N
btniniciar.setForeground(java.awt.Color.blue);
btniniciar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/musica.png"))); // NOI18N
btniniciar.setText("Iniciar");
btniniciar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btniniciarActionPerformed(evt);
}
});
lblnota.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.red, 2));
jLabel1.setFont(new java.awt.Font("Arial", 1, 22)); // NOI18N
jLabel1.setForeground(java.awt.Color.blue);
jLabel1.setText("Nota :");
jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel1MouseClicked(evt);
}
});
jLabel10.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
jLabel10.setForeground(java.awt.Color.red);
jLabel10.setText("TOCAR MÚSICAS");
jLabel2.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jLabel2.setForeground(java.awt.Color.blue);
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/dj_peq.png"))); // NOI18N
jLabel2.setText("Música :");
txtposicao.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
txtposicao.setForeground(java.awt.Color.red);
txttempo.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel3.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jLabel3.setForeground(java.awt.Color.red);
jLabel3.setText("Tempo da Música (Seg)");
txtareamus.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.red, 2));
txtareamus.setFont(new java.awt.Font("Arial", 1, 20)); // NOI18N
txtareamus.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
txtareamusMouseEntered(evt);
}
public void mousePressed(java.awt.event.MouseEvent evt) {
txtareamusMousePressed(evt);
}
});
jScrollPane1.setViewportView(txtareamus);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 825, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(txtposicao, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(132, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(515, 515, 515)
.addComponent(Btnsair))
.addComponent(lblnota, javax.swing.GroupLayout.PREFERRED_SIZE, 602, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(20, Short.MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addGap(238, 238, 238)
.addComponent(btniniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 248, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(78, 78, 78)
.addComponent(txttempo, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel3))
.addGap(217, 217, 217))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtposicao, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addComponent(lblnota, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(47, 47, 47)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txttempo, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
.addComponent(btniniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(53, 53, 53)
.addComponent(Btnsair))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2))
.addComponent(jLabel10))
.addGap(18, 18, 18)
.addComponent(jScrollPane1)))
.addContainerGap())
);
setBounds(3, 0, 1499, 723);
}// </editor-fold>
private void BtnsairActionPerformed(java.awt.event.ActionEvent evt) {
executor.shutdownNow(); //Tentei este comando mas não funcionou.
this.dispose();
}
boolean isRunning = false;
ScheduledThreadPoolExecutor executor;
private void btniniciarActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println(totalLin);
if (isRunning) {
executor.shutdown();
isRunning = false;
}
executor = new ScheduledThreadPoolExecutor(1);
isRunning = true;
executor.scheduleAtFixedRate(() -> {
c = cifras.get(current);
try {
txtareamus.getHighlighter().removeAllHighlights();
txtareamus.getHighlighter().addHighlight(c.inicio, c.fim,
new DefaultHighlighter.DefaultHighlightPainter(Color.cyan));
} catch (BadLocationException ex) {
Logger.getLogger(FrmMusicaPlay.class.getName()).log(Level.SEVERE, null, ex);
}
String nova = c.name.replace("/", "_");
txtposicao.setText(nova);
ImageIcon imageIcon = new ImageIcon(new ImageIcon(caminhoDasNotas +
txtposicao.getText() + ".jpg").getImage().getScaledInstance(599, 243,
Image.SCALE_DEFAULT));
lblnota.setIcon(imageIcon);
current++;
}, 0, Integer.parseInt(txttempo.getText()), TimeUnit.SECONDS);
String selecionado = txtareamus.getSelectedText();
}
private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {
//não usado
}
private void txtareamusMousePressed(java.awt.event.MouseEvent evt) {
String selecionado = txtareamus.getSelectedText();
txtposicao.setText(selecionado);
ImageIcon imageIcon = new ImageIcon(new ImageIcon("C://MUSIC PLAY//NotasTeclado//"+
txtposicao.getText()+ ".jpg").getImage().getScaledInstance(599,243,Image.SCALE_DEFAULT));
lblnota.setIcon(imageIcon);
}
private void txtareamusMouseEntered(java.awt.event.MouseEvent evt) {
//não usado
}
// Variables declaration - do not modify
private javax.swing.JButton Btnsair;
private javax.swing.JButton btniniciar;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblnota;
private javax.swing.JTextPane txtareamus;
private javax.swing.JTextField txtposicao;
public javax.swing.JTextField txttempo;
// End of variables declaration
}
identar texto pré-formatado por 4 espaços
Obrigado.