protected void buildErrorPanel() { errorPanel = new JPanel(); GroupLayout layout = new GroupLayout(errorPanel); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); errorPanel.setLayout(layout); // errorPanel.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, Color.BLACK)); errorMessage = new JTextPane(); errorMessage.setEditable(false); errorMessage.setContentType("text/html"); errorMessage.setText( "<html><body>Could not connect to the Processing server.<br>" + "Contributions cannot be installed or updated without an Internet connection.<br>" + "Please verify your network connection again, then try connecting again.</body></html>"); errorMessage.setFont(Toolkit.getSansFont(14, Font.PLAIN)); errorMessage.setMaximumSize(new Dimension(550, 50)); errorMessage.setOpaque(false); StyledDocument doc = errorMessage.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); closeButton = new JButton("X"); closeButton.setContentAreaFilled(false); closeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { contribDialog.makeAndShowTab(false, false); } }); tryAgainButton = new JButton("Try Again"); tryAgainButton.setFont(Toolkit.getSansFont(14, Font.PLAIN)); tryAgainButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { contribDialog.makeAndShowTab(false, true); contribDialog.downloadAndUpdateContributionListing(editor.getBase()); } }); layout.setHorizontalGroup( layout .createSequentialGroup() .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(errorMessage) .addComponent( tryAgainButton, StatusPanel.BUTTON_WIDTH, StatusPanel.BUTTON_WIDTH, StatusPanel.BUTTON_WIDTH)) .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(closeButton)); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout.createParallelGroup().addComponent(errorMessage).addComponent(closeButton)) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(tryAgainButton)); errorPanel.setBackground(Color.PINK); errorPanel.validate(); }
public DocumentPanel() { super(new BorderLayout()); JLabel lblDocument = new JLabel("Document: " + document.getTitle()); lblDocument.setBorder(new EtchedBorder()); textPane = new JTextPane(document); textPane.setEditable(false); textPane.setMargin(new Insets(5, 20, 5, 5)); textPane.setMaximumSize(new Dimension(364, 1000000000)); textPane.setPreferredSize(new Dimension(364, 400)); textPane.setMinimumSize(new Dimension(364, 10)); textPane.addCaretListener( new CaretListener() { public void caretUpdate(CaretEvent e) { int length = document.getLength(); int offset = e.getDot(); if (e.getDot() == e.getMark()) textPane.getCaret().moveDot(offset + 1); Paragraph p = lockManager.getParFromOffset(offset); int pOffset = p.getOffset(); lblCursor.setText( "Document Length=" + String.valueOf(length) + ", CaretOffset=" + String.valueOf(offset) + ", Paragraph=" + p.toString() + ", Offset in Paragraph=" + String.valueOf(offset - p.getOffset())); } }); Box box = new Box(BoxLayout.X_AXIS); box.add(textPane); box.add(Box.createGlue()); box.setBackground(Color.WHITE); box.setOpaque(true); box.setPreferredSize(new Dimension(600, 10000)); lblCursor = new JLabel("Cursor"); lblCursor.setBorder(new EtchedBorder()); JPanel boxText = new JPanel(new BorderLayout()); boxText.setBorder(new EmptyBorder(5, 5, 5, 5)); boxText.add(lblDocument, BorderLayout.NORTH); boxText.add(new JScrollPane(box), BorderLayout.CENTER); boxText.add(lblCursor, BorderLayout.SOUTH); JLabel lblPars = new JLabel("Paragraphs: "); lblPars.setBorder(new EtchedBorder()); parList = new JList(); parList.setPreferredSize(new Dimension(100, 300)); parList.setEnabled(false); JPanel boxPars = new JPanel(new BorderLayout()); boxPars.setBorder(new EmptyBorder(5, 5, 5, 5)); boxPars.add(lblPars, BorderLayout.NORTH); boxPars.add(new JScrollPane(parList), BorderLayout.CENTER); add(boxText, BorderLayout.CENTER); add(boxPars, BorderLayout.EAST); }