📄 starsinfortablepanel.java
字号:
/* * StarsInforTablePanel.java * * Created on January 13, 2002, 9:03 PM */package org.impact.stars.appclient.common;import java.util.*;/** * * @author cai */public class StarsInforTablePanel extends javax.swing.JPanel { /** Creates new form InforTable */ public StarsInforTablePanel() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() { /* QuestionRowPanel questionPanel1 = new QuestionRowPanel(); panelVector = new Vector(); panelVector.add(questionPanel1); */ panelVector = new Vector(); HashMap ahmp = new HashMap(); ahmp.put("Question", "answer"); ahmp.put("Question2", "answer2"); setTableData(ahmp); /* jTextArea1 = new javax.swing.JTextArea(); jScrollPane3 = new javax.swing.JScrollPane(); jTextPane2 = new javax.swing.JTextPane(); */ setMinimumSize(new java.awt.Dimension(372, 800)); showQuestion(); } private void removeQuestion(){ Enumeration eum = panelVector.elements(); while (eum.hasMoreElements()) { remove((QuestionRowPanel)eum.nextElement()); } }private void showQuestion(){ setLayout(new java.awt.GridLayout(panelVector.size(), 1, 10, 5)); Enumeration eum = panelVector.elements(); while (eum.hasMoreElements()) { add((QuestionRowPanel)eum.nextElement()); }}public void addQuestionRow(){ QuestionRowPanel questionPanel = new QuestionRowPanel(); questionPanel.getTextAreaQ().setEditable(true); panelVector.addElement(questionPanel); // Vector add(questionPanel); //currentRowPanel = questionPanel; setLayout(new java.awt.GridLayout(panelVector.size(), 1, 10, 5)); repaint();}public void removeQuestionRow(){ Iterator it = panelVector.iterator(); currentRowPanel = (QuestionRowPanel)panelVector.lastElement(); //QuestionRowPanel qp = null; /* while(it.hasNext()) { qp = (QuestionRowPanel)it.next(); System.out.println("remove:" + qp.getTextPaneQ().hasFocus()); it.remove(); qp.setVisible(false); //qp.dispose(); remove(qp); if (qp.getTextPaneQ().hasFocus()) { it.remove(); qp.setVisible(false); //qp.dispose(); remove(qp); } } */ if (currentRowPanel != null) { remove(currentRowPanel); panelVector.remove(currentRowPanel); } repaint();}public QuestionRowPanel getQuestionRow(int index){ return (QuestionRowPanel)panelVector.get(index);}//set the data to be displayed by the panelpublic void setTableData(HashMap aDataMap){ removeQuestion(); panelVector.removeAllElements(); Set set = aDataMap.entrySet(); Iterator mapit = set.iterator(); while(mapit.hasNext()) { Map.Entry me = (Map.Entry)mapit.next(); QuestionRowPanel qP = new QuestionRowPanel(); qP.setQuestion((String)me.getKey()); qP.setAnswer((String)me.getValue()); panelVector.add(qP); } showQuestion();}public HashMap getTableData(){ HashMap aDataMap = new HashMap(); Iterator it = panelVector.iterator(); QuestionRowPanel qp = null; while(it.hasNext()) { qp = (QuestionRowPanel)it.next(); aDataMap.put(qp.getQuestion(), qp.getAnswer()); } return aDataMap;}private class QuestionRowPanel extends javax.swing.JPanel { private javax.swing.JTextArea jTextAreaQ; private javax.swing.JScrollPane jScrollPaneQ; private javax.swing.JTextPane jTextPaneQ; public QuestionRowPanel () { jTextAreaQ = new javax.swing.JTextArea(); jTextAreaQ.setRows(4); jTextAreaQ.setWrapStyleWord(true); jScrollPaneQ = new javax.swing.JScrollPane(); jTextPaneQ = new javax.swing.JTextPane(); jTextPaneQ.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent e) { //currentRowPanel = (QuestionRowPanel)(getParent()); } }); this.setLayout(new java.awt.GridLayout(1, 2, 5, 5)); this.setBorder(new javax.swing.border.LineBorder(java.awt.Color.black)); this.setMinimumSize(new java.awt.Dimension(100, 60)); this.setMaximumSize(new java.awt.Dimension(300, 300)); this.setPreferredSize(new java.awt.Dimension(100, 100)); jTextAreaQ.setLineWrap(true); jTextAreaQ.setEditable(false); jScrollPaneQ.setViewportView(jTextPaneQ); add(jTextAreaQ); add(jScrollPaneQ); } public javax.swing.JTextPane getTextPaneQ() { return jTextPaneQ; } public javax.swing.JTextArea getTextAreaQ() { return jTextAreaQ; } public void setQuestion(String q) { jTextAreaQ.setText(q); } public void setAnswer(String q) { jTextPaneQ.setText(q); } public String getQuestion() { return jTextAreaQ.getText(); } public String getAnswer() { return jTextPaneQ.getText(); }}private java.util.Vector panelVector;private QuestionRowPanel currentRowPanel; // Variables declaration - do not modify// End of variables declaration}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -