My JTextArea's are not respecting the size of the component and are being cut off

ErlichBachman :

I have been working on this for hours. I honestly cannot figure it out. I have JTextArea's inside a JSplitPane which is inside a JPanel with a JButton and all that is put in my JFrame. I am using Layout managers. I have tried using pack(). I have tried using preferred sizes. Without the JPanel my button does not display in the proper location or switch buttons in other Tabs. With the JPanel it cuts off all my text, stops the scroll function(yes I have tried setting the TextAreas to always have horizontal and vertical scroll bars...does not solve the problem where text just stops wrapping for no apparent reason).

public static void main(String[] args) throws IOException
{
    JFrame frame = new JFrame();

    Deck blackjack = new Deck(Deck.TYPE[0]);

    JTextArea textBlackjackUnshuffled = new JTextArea();
    JTextArea textBlackjackShuffle = new JTextArea();

    JButton shuffleButtonBlackjack = new JButton(new ImageIcon(ImageIO.read(new File("res/shuffle.png"))));

    JToolBar toolBarBlackjack = new JToolBar("Blackjack");

    JSplitPane splitPaneBlackjack = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

    JPanel panel = new JPanel();

    JTabbedPane tabbedPaneBlackJack = new JTabbedPane();
    JTabbedPane tabbedPaneCanasta = new JTabbedPane();
    JTabbedPane tabbedPanePinochle = new JTabbedPane();

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());


    textBlackjackUnshuffled.setColumns(10);
    textBlackjackUnshuffled.setLineWrap(true);
    textBlackjackUnshuffled.setWrapStyleWord(true);
    textBlackjackUnshuffled.setEditable(false);
    textBlackjackUnshuffled.setFont(new Font("DejaVu Sans", Font.PLAIN, 100));
    textBlackjackUnshuffled.append(blackjack.toString());

    textBlackjackShuffle.setColumns(10);
    textBlackjackShuffle.setLineWrap(true);
    textBlackjackShuffle.setWrapStyleWord(true);
    textBlackjackShuffle.setEditable(false);
    textBlackjackShuffle.setFont(new Font("DejaVu Sans", Font.PLAIN, 100));
    textBlackjackShuffle.append(blackjack.toString());

    shuffleButtonBlackjack.setBorderPainted(false);
    shuffleButtonBlackjack.setFocusPainted(false);
    shuffleButtonBlackjack.setContentAreaFilled(false);

    splitPaneBlackjack.add(new JScrollPane(textBlackjackUnshuffled));
    splitPaneBlackjack.add(new JScrollPane(textBlackjackShuffle));

    panel.add(splitPaneBlackjack, BorderLayout.CENTER);
    panel.add(shuffleButtonBlackjack, BorderLayout.PAGE_END);

    tabbedPaneBlackJack.addTab("Blackjack", panel);

    frame.add(tabbedPaneBlackJack);
    frame.setSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize()));
    frame.setVisible(true);
}
Hovercraft Full Of Eels :

You're adding the JScrollPanes to the panel in BorderLayout positions, but have not set the layout manager of panel to BorderLayout. In this situation, panel will be using JPanel's default layout manager, FlowLayout, a manager which is not smart enough to respect the scroll pane's preferred sizes.

Your code needs:

panel.setLayout(new BorderLayout());

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=416673&siteId=1