for (int i = 0; i < length; i++) { List<String> strs = new ArrayList<>(); // Object[] objs=trials.get(i); String dnadata = (String) xulieDatas.get(i)[7]; if (dnadata.length() > 0) { JLabel jep = new JLabel(); jep.setFont(new Font("宋体",0,16));//加粗 maxlen = Math.max(dnadata.length() * 6 * 1.5f, maxlen); jep.setPreferredSize(new Dimension((int) (dnadata.length() * 6 * 1.5), height)); dnadata=dnadata.replaceAll("A","<font size='5' color =green>A</font>"); dnadata=dnadata.replaceAll("G","<font size='5' color =black>G</font>"); dnadata=dnadata.replaceAll("T","<font size='5' color =red>T</font>"); dnadata=dnadata.replaceAll("C","<font size='5' color =blue style='border:1px solid;color =blue;'>C</font>"); dnadata=dnadata.replaceAll("N","<font size='5' style='font-weight:bold;'color =blue><u>N</u></font>"); jep.setText("<html>" + dnadata + "</html>"); jep.setName(xulieDatas.get(i)[2] + ""); //----------------- // JTextPane jep = new JTextPane(); // jep.setPreferredSize(new Dimension(1250, height)); // jep.setContentType("text/html"); // StyledDocument doc = jep.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); // jep.setText(sb.toString()); jLabels.add(jep); } }