/** Creates new form QuestionPanel */ public SubQuestionPanel(final StandardsController ssController, Question subQuestion) { this.ssController = ssController; this.subQuestion = subQuestion; initComponents(); finalHeight = 0; BoxLayout boxLayout = new BoxLayout(containPanel, BoxLayout.Y_AXIS); containPanel.setLayout(boxLayout); String subQuestionDesc = subQuestion.getDescription().getDescriptionValue().toString(); descPanel = new QuestionDescPanel(); descPanel.getDescTextArea().setText(subQuestionDesc); FontMetrics fm = descPanel.getDescTextArea().getFontMetrics(descPanel.getDescTextArea().getFont()); List<String> texts = new ArrayList<String>(); Dimension d = descPanel.getDescTextArea().getPreferredSize(); String text = descPanel.getDescTextArea().getText(); String line = ""; for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (c != '\n') { if (fm.stringWidth(line + c) <= d.width) { line += c; } else { texts.add(line); line = "" + c; } } } texts.add(line); descPanel.getDescTextArea().setRows(texts.size()); descPanel.setPreferredSize( new Dimension( descPanel.getDescTextArea().getPreferredSize().width, descPanel.getDescTextArea().getRows() * 20)); descPanel.addMouseWheelListener( new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { JScrollBar scrollBar = ssController .getDisplayQuestions() .getStandardsPanel() .getjScrollPane() .getVerticalScrollBar(); scrollBar.setValue(scrollBar.getValue() + e.getWheelRotation() * 20); } }); setFinalDescHeight(descPanel.getDescTextArea().getRows() * 20); choiceContainer = ssController.getDisplayQuestions().formatedChoiceContainer(subQuestion, this); initialContainPanel(); }
public void addChoiceContainer() { Container newChoiceContainer = ssController.getDisplayQuestions().formatedChoiceContainer(subQuestion, this); containPanel.add(newChoiceContainer); choiceContainer = newChoiceContainer; }