0
我想添加一個滾動條到我的JTextarea,但滾動條不顯示我的Jtoolbar 任何人都可以告訴我這段代碼有什麼問題。所以我可以修復它。我一直在尋找eeverywhere但滾動窗格還是老樣子不露面JScrollPane不顯示到JTextarea
public PlayerGui() {
// create main windows
super("Liste");
JTextArea editors = new JTextArea();
editors.setLineWrap(true);
editors.setWrapStyleWord(true);
// scroll bar
JScrollPane scroll = new JScrollPane(editors);
setEditor(editors);
// create center panel
JPanel cent = new JPanel();
//create Panel for the to
JPanel north = new JPanel();
setNorthpanel(north);
// create tool bar
JToolBar toolbar = new JToolBar();
toolbar.add(scroll);
// set center panel and add preffered layout and backgrounds and size
setCenter(cent);
getCenter().setLayout(new BorderLayout());
// add scroll bar and toolbar
add(scroll, BorderLayout.EAST);
add(toolbar, BorderLayout.SOUTH);
//getCenter().setBackground(Color.black);
Dimension size = new Dimension(getCenter().getPreferredSize());
getEditor().setPreferredSize(size);
getCenter().getPreferredSize();
getCenter().setBorder(new CompoundBorder(new EmptyBorder(10,10 ,10,10),new EtchedBorder(Color.BLACK, Color.black)));
//add text editor to the center panel
getCenter().add(getEditor(),BorderLayout.CENTER);
//set layout of the frame
setLayout(new BorderLayout());
menubar1 = new JMenuBar();
//create menu list from a string arrays
for(int i=0; i<list.length; i++){
JMenu menus = new JMenu(list[i]);
menubar1.add(menus);
}
發佈證明你的問題的[SSCCE](http://sscce.org/)。我們不知道setEditor(...)方法的作用。由於它使用文本區域,可能這是問題的原因。 – camickr
'getCenter()。getPreferredSize();'嗯..你期望達到什麼目的? –