gpt4 book ai didi

Java GUI 填充空白

转载 作者:行者123 更新时间:2023-12-01 19:35:12 24 4
gpt4 key购买 nike

Java GUI我的项目有以下 Java GUI。由于某种原因,中间和右侧面板被放置在下面,留下空白区域 - 标记为红色。有没有办法将面板拉起来以填充空间。

这些空白看起来不太好。我尝试检查所有代码,但无法确定要纠正的位置。

提前致谢。

     public static JPanel main= new JPanel(), 
left= new JPanel(),middle= new JPanel(),right = new JPanel();

Container c = getContentPane();
c.setLayout(new FlowLayout()) ;

JPanel pane = new JPanel();
pane.setLayout(new BorderLayout());
pane.add(new JLabel("Enter word/SQL: "), "North");
pane.add(tf, "Center"); //enter keyword

JPanel second = new JPanel();
second.setLayout(new GridLayout(8, 1));
second.add(messageIDText);

//This is the start of adding panels
//create a left side panal and add the sub panels to it
JPanel left = new JPanel();
JPanel middle = new JPanel();
JPanel center = new JPanel();
JTextArea output = new JTextArea("", 60, 60);
JPanel sixth = new JPanel();
JPanel seventh = new JPanel();
JPanel eigth = new JPanel(new GridLayout(8,1));
JPanel labels7 = new JPanel(new GridLayout(5,1));
JPanel controls7 = new JPanel(new GridLayout(5,1));
JPanel tenth = new JPanel();
sixth.setLayout(new BorderLayout(5,5));

JPanel fourth = new JPanel();
fourth.add(firstButton);
sixth.add(labels, BorderLayout.WEST);
sixth.add(controls, BorderLayout.CENTER);
sixth.add(controlsButtons, BorderLayout.EAST);
labels.add(new JLabel("Proposal:"));
controls.add(proposalNumberText);
controlsButtons.add(freeQueryButton);

//add border
pane.setBorder(BorderFactory.createCompoundBorder(new
EmptyBorder(10,10,10,10), BorderFactory.createEtchedBorder()));
fourth.setBorder(BorderFactory.createCompoundBorder(new
EmptyBorder(10,10,10,10), BorderFactory.createEtchedBorder()));

//-------LEFT SIDE -- PARAMETERS
left.setLayout(new BoxLayout(left, BoxLayout.PAGE_AXIS));
JLabel headerLabel,blank;
headerLabel = new JLabel("Navigate Records", JLabel.LEFT);
Font f = headerLabel.getFont();
headerLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD)); // bold
left.add(headerLabel, BorderLayout.PAGE_END);
left.add(fourth, BorderLayout.PAGE_END);

main.add(left);

//---------MIDDLE PART - Messages - tabbed pane
JTabbedPane jtp = new JTabbedPane();
getContentPane().add(jtp);
//jtp.setSize(jtp.getPreferredSize());
JPanel jpA = new JPanel(),jpB = new JPanel(),
jpC = new JPanel(),jpD = new JPanel();
JScrollPane scrollPane2 = new JScrollPane(),jp = new
JScrollPane(activeTSText), jp2 = new JScrollPane(analyseWordsText),
jp3 = new JScrollPane(markedMessageText);
JLabel labelA = new JLabel();
labelA.setText("");
jpA.add(labelA);
jpA.add(jp);

jtp.addTab("Message", jpA);
middle.add(jtp);
main.add(middle);

//----------RIGHT PART - .. //paramters and results
JPanel jj = new JPanel();
jj.setLayout(new BoxLayout(jj, BoxLayout.PAGE_AXIS));
stateJTable.setRowHeight(20); //add JTable
JScrollPane js3 =new JScrollPane(stateJTable);
js3.setVisible(true);

//JTabbedPane jtp2 = new JTabbedPane();
//JPanel StateSubstatesTabOnLeft = new JPanel(),
StateSubstates_PostProcessedTabOnLeft = new JPanel();
JPanel firstleftTabinRightSideOfFrame = new JPanel(),
secondLeftTabinRightSideOfFrame = new
JPanel(),rightTabInRightSideOfFrame = new JPanel();

jj.add(js3);
//downbelow, the state jtable is added to the panel here through the
//scrollpane which contains the jtable

right.add(jj) ; //stateJTable);// add table in panel using add() method
main.add(right);
proposalNumberText.requestFocusInWindow();

最佳答案

我已经通过使用 Borderlayout 并将主面板分配给它解决了这个问题。为其分配 WEST、CENTER 和 EAST 区域。

我已在上面的代码中添加主面板的位置添加了下面的代码。

感谢您提供使用 MRE 方法开始调试的建议。

BorderLayout layout = new BorderLayout();
main.setLayout(layout);
main.add(left,BorderLayout.WEST);
main.add(middle,BorderLayout.CENTER);
main.add(right,BorderLayout.EAST);

关于Java GUI 填充空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59228532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com