Builds a JPanel containing the supplied message, split at each new line and an optional checkbox, suitable for use in a showMessageDialog call. This is generally useful for showing messges which can turned off either in preferences or when they are displayed. @param message The message to be displa
(String message, JCheckBox checkbox)
| 1327 | * @return JPanel A panel containing the message and the checkbox. |
| 1328 | */ |
| 1329 | public static JPanel buildMessageLabelPanel(String message, JCheckBox checkbox) |
| 1330 | { |
| 1331 | JPanel panel = new JPanel(); |
| 1332 | JLabel label; |
| 1333 | String part; |
| 1334 | |
| 1335 | panel.setLayout(new GridBagLayout()); |
| 1336 | |
| 1337 | GridBagConstraints cons = new GridBagConstraints(); |
| 1338 | cons.gridx = cons.gridy = 0; |
| 1339 | cons.gridwidth = GridBagConstraints.REMAINDER; |
| 1340 | cons.gridheight = 1; |
| 1341 | cons.anchor = GridBagConstraints.WEST; |
| 1342 | cons.insets = new Insets(0, 0, 3, 0); |
| 1343 | cons.weightx = 1; |
| 1344 | cons.weighty = 0; |
| 1345 | cons.fill = GridBagConstraints.NONE; |
| 1346 | |
| 1347 | int start = 0; |
| 1348 | int sepPos; |
| 1349 | |
| 1350 | do |
| 1351 | { |
| 1352 | sepPos = message.indexOf("\n", start); //$NON-NLS-1$ |
| 1353 | |
| 1354 | if (sepPos >= 0) |
| 1355 | { |
| 1356 | part = message.substring(start, sepPos); |
| 1357 | start = sepPos + 1; |
| 1358 | } |
| 1359 | else |
| 1360 | { |
| 1361 | part = message.substring(start); |
| 1362 | start = -1; |
| 1363 | } |
| 1364 | |
| 1365 | label = new JLabel(part, SwingConstants.LEADING); |
| 1366 | |
| 1367 | panel.add(label, cons); |
| 1368 | cons.gridy++; |
| 1369 | } |
| 1370 | while (start >= 0); |
| 1371 | |
| 1372 | if (checkbox != null) |
| 1373 | { |
| 1374 | label = new JLabel("", SwingConstants.LEADING); //$NON-NLS-1$ |
| 1375 | panel.add(label, cons); |
| 1376 | cons.gridy++; |
| 1377 | panel.add(checkbox, cons); |
| 1378 | cons.gridy++; |
| 1379 | } |
| 1380 | |
| 1381 | return panel; |
| 1382 | } |
| 1383 | |
| 1384 | @Override |
| 1385 | public Boolean maybeShowWarningConfirm(String title, String message, String checkBoxText, |
no test coverage detected