Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Frame;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.ScrollPaneConstants;
- import javax.swing.UIManager;
- public class Test {
- JFrame frame;
- public Test() {
- frame = new JFrame();
- frame.setBounds(100, 100, 740, 580);
- frame.getContentPane().setMinimumSize(new Dimension(640, 480));
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- final JScrollPane scrollPane = new JScrollPane();
- frame.add(scrollPane);
- scrollPane.setViewportView(new ProgPanel());
- }
- public static void main(String[] args) {
- Test t = new Test();
- t.frame.setVisible(true);
- }
- public class ProgPanel extends JPanel {
- /**
- * Create the panel.
- */
- public ProgPanel() {
- GridBagLayout gridBagLayout = new GridBagLayout();
- gridBagLayout.columnWidths = new int[]{0, 0};
- gridBagLayout.rowHeights = new int[]{59, 0, 0};
- gridBagLayout.columnWeights = new double[]{0.0, 1.0};
- gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
- setLayout(gridBagLayout);
- JWrappingText wrpngtxtTest = new JWrappingText("Long, long text taht needs to be wrapped, because it is displayed in a very big font on a kindof small screen, bla bla bla bhlergh lol rofl 1337");
- wrpngtxtTest.setFont(wrpngtxtTest.getFont().deriveFont(Font.BOLD, 48));
- GridBagConstraints gbc_wrpngtxtTest = new GridBagConstraints();
- gbc_wrpngtxtTest.fill = GridBagConstraints.HORIZONTAL;
- gbc_wrpngtxtTest.insets = new Insets(0, 10, 5, 0);
- gbc_wrpngtxtTest.gridx = 1;
- gbc_wrpngtxtTest.gridy = 0;
- add(wrpngtxtTest, gbc_wrpngtxtTest);
- }
- }
- public class JWrappingText extends JTextArea {
- public JWrappingText(String str) {
- super(str);
- setLineWrap(true);
- setWrapStyleWord(true);
- setOpaque(false);
- setEditable(false);
- setFocusable(false);
- setBackground(UIManager.getColor("Label.background"));
- setFont(UIManager.getFont("Label.font"));
- setBorder(UIManager.getBorder("Label.border"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement