JScrollPane pane = new JScrollPane();
JPanel panel = new JPanel();
panel.add(pane);
How to add jScrollPane to Null Layout of jPanel [closed]
-
07-12-2021 - |
Question
How to add jScrollPane
to Null Layout of jPanel
in netbeans
? i am using Null Layout for jPanel
and i searched out on different sources but still I am failing to add jScrollPane to Null Layout of jPanel.
Please help with source code if possible.
Thanks for all replies commenter and also I am accepting advice and not talking about advice.
Here I seem when someone asks a question about any thing that they need but some people here discourage to someone who asks help instead of helping...
The basic need my using of null layout is, I am adding background image to jpanel using null layout with jlabel coz i am using netbeans and I am beginner of java...
I am requesting all moderators please don't remove my Edit words... people may understand my feeling coz i am java with netbeans learner.
Solution 2
OTHER TIPS
Instead of setting null
layout for your JPanel
, set BorderLayout
and everything should work fine like in this example:
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.JTextArea;
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
public class App extends JFrame{
JPanel panel = new JPanel();
JTextArea textarea = new JTextArea(10,50);
public App(){
panel.setLayout(new BorderLayout());
panel.add(new JScrollPane(textarea),BorderLayout.CENTER);
add(panel);
}
public static void main( String[] args ){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
App a = new App();
a.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
a.pack();
//a.setSize(1900,1200);
a.setVisible(true);
}
});
}
}
So, just add your form instead of JTextArea
.