كيف أضيف مساحة إلى JPanel، بحيث لا يجلس Jscrollpane أعلى مكوناتي؟

StackOverflow https://stackoverflow.com/questions/6059155

سؤال

لدي Jscrollpane وعندما أقوم بتحميل تطبيقي، يجلس الشريط على رأس أحد الأزرار الخاصة بي.ما أود القيام به هو إضافة بعض المساحة إلى جانب الزر الخاص بي بحيث يستمد شريط التمرير على المسافة وليس الزر الخاص بي.

مثال رمز حاولت: giveacodicetagpre.

المشكلة في هذا الرمز هو أنه لا يزال يبحث عن زر بلدي ولا يتم إضافة مساحة.ما هي أفضل طريقة للتأكد من أن Jscrollpane لا يتداخل المكونات في JFrame الخاص بي؟

شكرا

هل كانت مفيدة؟

المحلول

To ensure that the size of the JPanel is respected you should use setPreferredSize() instead of setSize().

نصائح أخرى

In your sample code, didn't you reverse EAST and WEST? Shouldn't it be like:

eButton.add(editButton, BorderLayout.WEST); 
eButton.add(spaceFiller, BorderLayout.EAST); 

That would make more sense, sicne the scrollbar will appear on the right side (EAST).

Please note that the solution you suggest, even though it may work (after exchanging EAST and WEST) looks more like a hack than a real solution.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top