我是靠谱客的博主 天真自行车,这篇文章主要介绍java绝对布局滚动条_Java swing,滚动条不能使用绝对布局,现在分享给大家,希望可以做个参考。

我希望jscrollpane中没有布局管理器的jpanel固定大小(也没有布局管理器).我不能使用任何布局管理器,因为我需要在用户点击的位置创建一个矩形/圆(并允许拖放所有创建的emelents)

setLocationRelativeTo(null);

setSize(300,300);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setName("dnd test");

int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;

int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;

JScrollPane scroll = new JScrollPane(panel,v,h);

scroll.setLayout(null);

scroll.setPreferredSize(new Dimension(1000, 1000));

scroll.setBounds(0, 0, 1000, 1000);

panel = buildComponentOnAbsoluteLayout(new JPanel(),scroll,0,0,500,500);

panel.setBackground(Color.darkGray);

panel.setSize(350,350);

panel.setLayout(null);

buildComponentOnAbsoluteLayout(new JButton("button 1"),panel,10,10,120,30);

buildComponentOnAbsoluteLayout(new JButton("button 1"),panel,50,50,120,30);

add(scroll);

setVisible(true);

public static T buildComponentOnAbsoluteLayout(T t,Container holder,int x, int y,int width, int heigth){

t.setBounds(x,y,width,heigth);

holder.add(t);

return t;

}

滚动条永远不会弹出.

最后

以上就是天真自行车最近收集整理的关于java绝对布局滚动条_Java swing,滚动条不能使用绝对布局的全部内容,更多相关java绝对布局滚动条_Java内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(38)

评论列表共有 0 条评论

立即
投稿
返回
顶部