jpanel

How do I scroll JScrollPane viewport containing a JPanel to a specific location

吃可爱长大的小学妹 提交于 2020-01-14 10:23:41
问题 I am trying to create a large game board that only part of it will be visible in the viewport and would like to be able to move the viewport around using the arrow keys to see the whole board. Right now I have a JScrollPane that contains a JPanel that will have Images and text and other stuff, but those are irrelevant. Right now I have an ImageIcon at the same size as the JPanel as a background and I would like to have an option to move the viewport around by using keys, and not have any

How do I scroll JScrollPane viewport containing a JPanel to a specific location

拈花ヽ惹草 提交于 2020-01-14 10:23:31
问题 I am trying to create a large game board that only part of it will be visible in the viewport and would like to be able to move the viewport around using the arrow keys to see the whole board. Right now I have a JScrollPane that contains a JPanel that will have Images and text and other stuff, but those are irrelevant. Right now I have an ImageIcon at the same size as the JPanel as a background and I would like to have an option to move the viewport around by using keys, and not have any

Swing: hovering mouse over radio button label on translucent JPanel

≯℡__Kan透↙ 提交于 2020-01-14 08:37:25
问题 In my problem I have an opaque JPanel and another JPanel that is translucent(semi-transparent) which sits on the first JPanel. When I have added radio buttons onto the top JPanel. The problem is every time I enter mouse over the area of the label of each radio button(and every time I move mouse away from the label), it gets darker and darker. package trial; import java.awt.Color; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing

What is the best way to build a Minesweeper Board in a JFrame?

拜拜、爱过 提交于 2020-01-14 07:02:47
问题 I am just trying to construct a gameboard with tiles to work with. I got it to work by painting the tile into rows and columns with BufferedImage, but I am going to need to constantly update the GUI as the game is played. So I tried to add the tile image to an ImageIcon, then to a JLabel array so that I could set the position. After that I would add the labels to the gui JPanel, but they had these default gaps between them. Am I approaching this incorrectly? I am very new to Swing and Java

What is the best way to build a Minesweeper Board in a JFrame?

China☆狼群 提交于 2020-01-14 07:02:29
问题 I am just trying to construct a gameboard with tiles to work with. I got it to work by painting the tile into rows and columns with BufferedImage, but I am going to need to constantly update the GUI as the game is played. So I tried to add the tile image to an ImageIcon, then to a JLabel array so that I could set the position. After that I would add the labels to the gui JPanel, but they had these default gaps between them. Am I approaching this incorrectly? I am very new to Swing and Java

How to remove the padding between in the JPanel still using a flow layout?

大兔子大兔子 提交于 2020-01-13 08:06:47
问题 Here's the portion of my java application GUI that I have a question about. What this GUI consists is a blue JPanel(container) with default FlowLayout as LayoutManager that contains a Box which contains two JPanels(to remove the horizontal spacing or i could have used setHgaps to zero for that matter instead of a Box) that each contains a JLabel. Here's my code for creating that part of the GUI. private void setupSouth() { final JPanel southPanel = new JPanel(); southPanel.setBackground(Color

SetVisible(false) changes the layout of my components within my Panel

谁说我不能喝 提交于 2020-01-12 23:04:31
问题 How do I make the subpanels within my main panel stay where they are when I set one of the subpanels to be invisible? What I have looks like: [ (Panel1) (Panel2) (Panel3) (Panel4) ] When I do panel3.setVisible(false) it then looks like: [ (Panel1) (Panel2) (Panel4) ] I would like it to look like: [ (Panel1) (Panel2) (Panel4) ] I am using the GridBagLayout and my mainPanel declaration looks like: final JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints c = new

Set the same font for all component Java

感情迁移 提交于 2020-01-12 18:45:14
问题 I want to set a specific font for all component in a JPanel but I prefer that the question is still more general and not limited to the JPanel. How can I set the font to a list of component in a container (JFrame or JPanel)? 回答1: Here is a simple method that allows you to specify Font to the whole components tree under any Container (or just a simple Component, doesn't matter): public static void changeFont ( Component component, Font font ) { component.setFont ( font ); if ( component

How to initialize Graphics? because it says it was not initialized [closed]

血红的双手。 提交于 2020-01-11 14:35:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have this part of my code but it will not initialize and I do not know how to do it. It keeps giving me an error such as Exception in thread "main" java.lang.NullPointerException at memor.main(memor.java:131) import java.awt.*; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.GridLayout;

How can I replace one of two JPanels with another JPanel in Java?

烂漫一生 提交于 2020-01-11 11:42:11
问题 I designed an interface for the welcome screen with one JFrame included two JPanels (JPanel1 on right and JPanel2 on left). The buttons on the left is to switch the Panels in JPanel1. I want to press on a button to replace JPanel1 content with another JPanel but I don`t know how. Please help. 回答1: Here is a very simple example of something that should approximate your description. On the left, we have a hug button to toggle the content of the right panel. On the right, you have a panel with a