layout-manager

Set the size of JTextField fixed in a JPanel

懵懂的女人 提交于 2019-12-24 06:42:37
问题 for school I am working on a Java GUI program to store some administrative data. Now I want to display eventdata from my DB (mysql) into a JPanel with use of a JTextField, my problem is I can't get the size of the JTextField fixed as it always takes up a lot of place (see picture) Picture: http://postimg.org/image/5pcklo5n1/ Here's my code, anyone some tips? (I am new to java): public void editEvent() { JFrame frEventEdit = new JFrame ("Event Edit Menu"); frEventEdit.setDefaultCloseOperation

Swing layout - Using a grid while keeping component dimensions

﹥>﹥吖頭↗ 提交于 2019-12-24 06:28:45
问题 I'd like to make a login bar for an application and I can't figure out how to organize a series of JLabels and JTextFields such that they are organized in a horizontal grid without these same components being resized to fit each cell. I also want to make sure that the group of components isn't resized below a certain width. How can this be achieved? Edit: Thanks for the answers everyone. I'll have a look at MigLayout and SpringLayout later. Due to time constraints I'm going to have to make do

Swing layout - Using a grid while keeping component dimensions

不打扰是莪最后的温柔 提交于 2019-12-24 06:28:03
问题 I'd like to make a login bar for an application and I can't figure out how to organize a series of JLabels and JTextFields such that they are organized in a horizontal grid without these same components being resized to fit each cell. I also want to make sure that the group of components isn't resized below a certain width. How can this be achieved? Edit: Thanks for the answers everyone. I'll have a look at MigLayout and SpringLayout later. Due to time constraints I'm going to have to make do

GridBagLayout doesn't fill all the space

百般思念 提交于 2019-12-24 05:44:04
问题 I have a panel which is used as a part of card layout. The panel uses GridBagLayout . I add two components to it: JTextArea with fill set to BOTH and JTextField with fill set to horizontal. They are only taking up the horizontal space. // Chat card setup JPanel chatCard = new JPanel(new GridBagLayout()); gc = new GridBagConstraints(); gc.gridx = 0; gc.gridy = 0; gc.fill = GridBagConstraints.BOTH; gc.weightx = 2; chatArea = new JTextArea(); chatCard.add(chatArea,gc); gc.gridx = 0; gc.gridy = 1

GridBagLayout doesn't fill all the space

假装没事ソ 提交于 2019-12-24 05:44:02
问题 I have a panel which is used as a part of card layout. The panel uses GridBagLayout . I add two components to it: JTextArea with fill set to BOTH and JTextField with fill set to horizontal. They are only taking up the horizontal space. // Chat card setup JPanel chatCard = new JPanel(new GridBagLayout()); gc = new GridBagConstraints(); gc.gridx = 0; gc.gridy = 0; gc.fill = GridBagConstraints.BOTH; gc.weightx = 2; chatArea = new JTextArea(); chatCard.add(chatArea,gc); gc.gridx = 0; gc.gridy = 1

how to set & manage the layout of JOptionPane

戏子无情 提交于 2019-12-24 05:34:12
问题 I have a simple JOptionPane with some components and I want to arrange them. For example I want to put the label next to the text/password field, sets their width etc.. This is like how I did it, of course the result wasn't what I wanted: public class CreateApplicationUserScreen { CreateApplicationUserScreen(){ JLabel l_name=new JLabel("Username"); JLabel l_pass=new JLabel("Password"); JTextField tf_name=new JTextField(10); JPasswordField pf_pass=new JPasswordField(10); JButton b_privs = new

I have a JApplet which has to display 3 Components. (2 JPanels and 1 Paint Method)

落花浮王杯 提交于 2019-12-24 01:19:07
问题 I have an assignment in which I have to allow a user to plot a graph using a quadratic equation. I managed to draw the skeleton of the graph, and now I am trying to display the "control panel" for the user to input the values. I have 4 files: graph.java panel.java panelB.java panelC.java My problem is when I run the code it is displaying only the panel.java even in the container where it should display the other two panels. panel.java import java.awt.Dimension; import java.awt.Graphics;

How do I position JButtons vertically one after another?

六月ゝ 毕业季﹏ 提交于 2019-12-24 00:13:30
问题 I used a CardLayout to create 2 panels. The one on the left hosts JButtons , which when clicked, opens the corresponding website in the right panel. The problem is that I'm unable to place the buttons one on top of the other. Please observe the screenshot below :- 回答1: "The problem is that I'm unable to place the buttons one after the other." You could use a Box set vertically JButton jbt1 = new JButton("Button1"); JButton jbt2 = new JButton("Button2"); JButton jbt3 = new JButton("Button3");

GridBag Layout How to push components north

余生颓废 提交于 2019-12-23 17:12:22
问题 Here's my code public class HomeTopPanel extends JPanel { //BUTTONS private final JButton myAccountButton = new JButton("My Account"); private final JButton updatePhoto = new JButton("Update Photo"); //PANELS private final JPanel rightPanel_1 = new JPanel(new GridBagLayout()); private final JPanel rightPanel_2 = new JPanel(new GridBagLayout()); private final JPanel logHistoryPanel = new JPanel(new GridBagLayout()); //BORDERS private final Border homeTopPanel_LineBorder = BorderFactory

JToolBar IllegalArgumentException when dropped back into GridBagLayout

守給你的承諾、 提交于 2019-12-23 15:15:54
问题 Why does this code throw an IllegalArgumentException when the tool bar is dragged off the GUI, then closed (to return it to the GUI)? I could understand why it might be improper to add a component with no constraint, but in this case, the initial addition of the toolbar to the panel (which uses GridBagLayout ) without a constraint causes no such problem. Why should it occur the 2nd and subsequent times it is added? The code is adapted from this answer, but both codes show the same problem.