Necesito mostrar los enlaces, así que estoy usando JTextPane con setContentType. Sin embargo, el contenido no se ajusta y no hay desplazamiento. El contenido de JTextPane se devolverá desde una fuente RSS. Aquí está el código completo:JTextPane no muestra JScrollPane y no ajusta el texto
import java.awt.*;
import javax.swing.*;
class Main extends JFrame
{
JFrame frame;
JTabbedPane tabbedPane;
JPanel home, news;
public Main()
{
setTitle("My Title");
setSize(900, 600);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
home();
news();
tabbedPane = new JTabbedPane();
tabbedPane.addTab(" Home", home);
tabbedPane.addTab("News", news);
JPanel framePanel = new JPanel();
framePanel.setLayout(new BorderLayout());
framePanel.add(tabbedPane, BorderLayout.CENTER);
getContentPane().add(framePanel);
}
public void home()
{
home = new JPanel();
// some stuffs here
}
public void news()
{
news = new JPanel();
JTextPane newsTextPane = new JTextPane();
newsTextPane.setContentType("text/html");
newsTextPane.setEditable(false);
JScrollPane scrollPane = new JScrollPane(newsTextPane);
scrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
news.add(scrollPane);
RSS reader = RSS .getInstance();
reader.writeNews();
String rssNews = reader.writeNews();
newsTextPane.setText(rssNews);
}
public static void main(String args[])
{
RSS reader = RSS.getInstance();
reader.writeNews();
Main mainFrame = new Main();
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
Mi resultado:
+1 para [sscce] (http://sscce.org/); Supongo que la pregunta (no vista) [markup] (http://stackoverflow.com/q/2645834/230513) y [contenedor] (http://stackoverflow.com/q/4702891/230513) también pueden ser un factor. – trashgod
@ Guillaume Polet +1 para el ejemplo, lo usé para mostrar que con un tamaño de contenedor incorrecto, la barra de desplazamiento no aparecerá. El OP está usando un 'panel' pero no sabemos lo suficiente al respecto. –
@trashgod, he incluido todo el código, por favor consejo! ¡Gracias! –