layout-manager

JButtons on GridLayout - MineSweeper

泪湿孤枕 提交于 2019-12-14 03:06:17
问题 I'm writing MineSweeper and using JButton s on a GridLayout . The numbers of rows and columns are entered by the user, so setting fixed size may cause several problems. How can I remove the space between the buttons without setting the fixed size of the panel? 回答1: This seems to be more of a issue with JButton then with GridLayout Here, I replaced JButton with JPanel (and some border magic) The other thing I tried was passing a negative h/vgap to the GridLayout I'd however not recommend this,

.pack() causes the components to be in the wrong place but works after window resize

我与影子孤独终老i 提交于 2019-12-14 02:35:03
问题 I am creating a game in java using Swing. I am using mainJFrame.setExtendedState(mainJFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH); on my JFrame to start it as a maximized window. After this I am using mainJFrame.pack(); to be able to get the correct x & y coordinates of components in the GUI. I need those coordinates since i'm painting custom images to the GUI. So far everything is fine. When a user has passed a level, i rebuild the GUI to updated it to the new level settings and then i

ImageIcon by JLabel example with absolute positioning

寵の児 提交于 2019-12-14 00:06:09
问题 I have seen a lot of example code but none that specifically shows me how to display an ImageIcon through the use of a JLabel on a JFrame without using a layout manager. I am repeatedly told that absolute positioning is a hassle and less efficient than a layout manager but I'd prefer complete control over where my elements are going. A full scale example class (with no extra things added) of a JLabel that will display an image on a JFrame with absolute positioning would be much appreciated ,

How to align multiple textfields on a background image within a JOptionPane?

旧街凉风 提交于 2019-12-13 18:31:55
问题 I want to have multiple textfiled to be aligned in a customized order, so that they are on the top of the background image. I tried to use setBounds but it did not work: import javax.swing.*; public class TestJP { public static void main(String[] args) { JLabel myLabel = new JLabel(); myLabel.setIcon ( new ImageIcon("system\\myBackground.jpg")); myLabel.setBounds(0,0,750,500); JTextField login = new JTextField(5); login.setBounds(50,50,20,100); // This does not work JPasswordField password =

Problems using RecyclerView with StaggeredLayoutManager

痞子三分冷 提交于 2019-12-13 16:47:18
问题 I succesfully implemented RecyclerView using StaggeredLayoutManager with 2 col/spans. I have variable heighted items in each col, heights are not fixed. Problem is, when I scroll down and up in RecyclerView, sometimes a gap is occured at the top item of one of the rows. I added a video describing my problem. I simply added a StaggeredLayout with span value 2, and adapted my items with an adapter. +-+-+-+-+-+-+-+-+-+-+-+-+ <------ Top of RecyclerView -------------- <- Top item in left column -

how do I add a JLabel to a specific location into my ScrollPane?

拥有回忆 提交于 2019-12-13 16:04:43
问题 Im trying to show images and/or labels in my JPanel. The thing is, I want to show many JLabels in custom locations but currently I can only show like 4 labels. I understand I need to use ScrollPane. I have tried using it but its not letting me alocate them with customs locations. (By custom locations I mean using coords to place my label.) Here is the code WITHOUT using ScrollPane: import java.awt.Dimension; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel;

Sizing a JScrollPane to take into account windows taskbar [duplicate]

被刻印的时光 ゝ 提交于 2019-12-13 09:41:28
问题 This question already has answers here : Sizing a JScrollPane in a JTabbedPane in a JFrame (2 answers) Closed 5 years ago . I am starting this new question because this question has been voted to close since it didnt have an MVCE. I have included the question with an SSCCE now. Please take a look at the below code import javax.swing.*; import java.awt.*; public class ScrollPaneTest { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run

How to make GridBagLayout specific size?

江枫思渺然 提交于 2019-12-13 08:38:51
问题 At the moment I've got a 9x9 grid of text fields using a GridBayLayout . Because the grid makes each text field slighter longer than it is tall (even when I set a specific height for the text field), the grid is a rectangle, rather than a square. How can I either make the entire grid a specific size, or each text field inside the grid a specific size? EDIT: I need the 9 x 9 grid of text fields to be square, rather than rectangular. 回答1: The problem is with sizing hints, methods [get/set]

JButtons don't load on panel until hovered over?

旧街凉风 提交于 2019-12-13 06:49:59
问题 When this is put on a frame, the buttons don't load until they are hovered over with the mouse, and then they stay up like they should. Here's the code: I've calling things like repaint() and revalidate() but none of them seem to have fixed the problem. The main and the Frame are seperate classes from the StartPanel. Thanks! JButton[][] levels = new JButton[3][8]; public StartPanel(){ setSize(1600, 1000); setLayout(null); int count = 1; int yValue = 150; for(int r = 0; r < 3; r++){ for(int c

Why does my JButton appear the full size of the JFrame?

青春壹個敷衍的年華 提交于 2019-12-13 06:27:16
问题 I am a newbie, I have a question. I am trying to use Eclipse to write a Java windows application, in which I will have a main window, which will contain several things, like a dashboard sort of thing, and it will have buttons, for example to add a record to a database, and this button when pressed, will open a new relevant window on top. I tried to start, I wrote this code in Java, and for some reason, the button is in the size of the frame...full screen ! How do I fix it ? Can you suggest me