------ Solution ---------------------------------------- ----
paste the code first . .
------ Solution ---------------------------------------- ----
setPreferredSize (Dimension preferredSize) to set the preferred size of this component
------ Solution --------------------- -----------------------
want to change the position you want to change the layout of the
------ Solution ------- -------------------------------------
you should not set this layout manager , so Jframe default to use the default layout manager .
you
jSP.setLayout (null);
Set layout manager is empty,
set directly controls the position and size
JTextArea.setBounds (x, y, width, height);
------ Solution ----------------- ---------------------------
jSP.setLayout (null); set to null after the text box on the not coming. .
how could I show here is normal ah , JSP, and taContent casually put the position and size ,
class MyPanel extends JPanel{
// JTextArea taText = new JTextArea(8,2);
JTextArea taContent = new JTextArea(12,59);
JScrollPane jSP = new JScrollPane(taContent);
Font f = new Font("宋体", Font.BOLD, 20);
public MyPanel(){
setLayout(null);
jSP.setBounds(5, 5, 600, 300);
jSP.setOpaque(false);
jSP.getViewport().setOpaque(false);
jSP.setLocation(7, 7);
this.add(jSP);
//taContent.setLocation(100, 200);
taContent.setLineWrap(true);
taContent.setOpaque(false);
taContent.setBackground(Color.blue);
taContent.setFont(f);
taContent.setSize(200,200);
jSP.setLayout(null);
taContent.setBounds(300,200, 100, 100);
jSP.add(taContent);
}
}
------ For reference only ----------------------------------- ----
this is part of the JPanel
public class MyPanel extends JPanel{
JTextArea taText = new JTextArea(8,2);
JTextArea taContent = new JTextArea(12,59);
JScrollPane jSP = new JScrollPane(taContent);
Font f = new Font("宋体", Font.BOLD, 20);
public MyPanel(){
jSP.setSize(600, 600);
jSP.setOpaque(false);
jSP.getViewport().setOpaque(false);
jSP.setLocation(7, 7);
this.add(jSP);
//taContent.setLocation(100, 200);
taContent.setLineWrap(true);
taContent.setOpaque(false);
taContent.setBackground(Color.blue);
taContent.setFont(f);
taContent.setSize(200,200);
}
This is part of the JFrame
public class MyFrame extends JFrame{
JButton jbEnter = new JButton("发送");
public MyFrame(String name){
super(name);
// this.setContentPane(new MyPanel());
this.add(new MyPanel());
this.setSize(800,450);
this.setResizable(false);
this.setDefaultCloseOperation(3);
this.setVisible(true);
}
}
------ For reference only ----------------------------------- ----
just tried, indeed can change the size, but can not change the position of ah.
------ For reference only -------------------------------------- -
jSP.setPreferredSize(new Dimension(800,450));
------ For reference only ---------------------------------- -----
Well, probably should be a kind of how to change the law? ?
------ For reference only -------------------------------------- -
jSP.setLayout (null); set to null after the text box to get out . .
------ For reference only -------------------------------------- -
jSP.setLayout (null); set to null after the text box to get out . .
how could I show here is normal ah , JSP, and taContent casually put the position and size ,
TU generally ok, thank you , thank you, there is a small problem is not resolved, I look back . .
class MyPanel extends JPanel{
// JTextArea taText = new JTextArea(8,2);
JTextArea taContent = new JTextArea(12,59);
JScrollPane jSP = new JScrollPane(taContent);
Font f = new Font("宋体", Font.BOLD, 20);
public MyPanel(){
setLayout(null);
jSP.setBounds(5, 5, 600, 300);
jSP.setOpaque(false);
jSP.getViewport().setOpaque(false);
jSP.setLocation(7, 7);
this.add(jSP);
//taContent.setLocation(100, 200);
taContent.setLineWrap(true);
taContent.setOpaque(false);
taContent.setBackground(Color.blue);
taContent.setFont(f);
taContent.setSize(200,200);
jSP.setLayout(null);
taContent.setBounds(300,200, 100, 100);
jSP.add(taContent);
}
}
没有评论:
发表评论