You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TitlePanel.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.ui_swing.components;
  18. import java.awt.Color;
  19. import javax.swing.BorderFactory;
  20. import javax.swing.JLabel;
  21. import javax.swing.JPanel;
  22. import javax.swing.border.Border;
  23. import net.miginfocom.swing.MigLayout;
  24. /**
  25. * Displays a title panel.
  26. */
  27. public class TitlePanel extends JPanel {
  28. /** A version number for this class. */
  29. private static final long serialVersionUID = -4026633984970698130L;
  30. /** Title label. */
  31. private final JLabel title;
  32. /**
  33. * Instantiates a new title panel.
  34. *
  35. * @param border Border to use for the panel
  36. */
  37. public TitlePanel(final Border border) {
  38. this(border, "");
  39. }
  40. /**
  41. * Instantiates a new title panel.
  42. *
  43. * @param text Initial text
  44. */
  45. public TitlePanel(final String text) {
  46. this(BorderFactory.createLineBorder(Color.BLACK), text);
  47. }
  48. /**
  49. * Instantiates a new title panel.
  50. *
  51. * @param border Border to use for the panel
  52. * @param text Initial text
  53. */
  54. public TitlePanel(final Border border, final String text) {
  55. super(new MigLayout());
  56. title = new JLabel(text);
  57. title.setFont(title.getFont().deriveFont((float) (title.getFont().
  58. getSize() * 1.5)));
  59. title.setForeground(Color.BLACK);
  60. title.setBackground(Color.WHITE);
  61. add(title, "grow, push");
  62. setBorder(border);
  63. setBackground(Color.WHITE);
  64. setForeground(Color.BLACK);
  65. }
  66. /**
  67. * Sets the text of this title panel.
  68. *
  69. * @param text New title text.
  70. */
  71. public void setText(final String text) {
  72. title.setText(text);
  73. }
  74. }