jpanel

GrahicsDevice and JOptionPane Issue

Deadly 提交于 2019-12-24 06:07:42
问题 When I click the button, the application which is set to full screen will go to taskbar/minimized, so I need to click it first in the taskbar before seeing the JOptionPane that I triggered. What do you think is the problem with this? I'd like it to run smoothly without being minimized or going to taskbar. public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setTitle("Sample"); GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment()

Draw lines on jpanel

ⅰ亾dé卋堺 提交于 2019-12-24 05:49:45
问题 I want to make it like Draw a ruler (line with tick marks at 90 degree angle) just not on jframe but on jpanel. So I tried: JFrame f = new JFrame(); JPanel ff = new JPanel(); ff.add(new JComponent() { ... }); f.add(ff); ... but I failed. :( How to? 回答1: You can simply override paintComponent(Graphics g){} for ff and draw your within that method. i.e. JPanel ff = new JPanel(){ public void paintComponent(Graphics g){ // Draw what you want to appear on your JPanel here. // g.drawLine(blah blah

Using MouseListener to select a range of cells in a grid

蓝咒 提交于 2019-12-24 03:36:27
问题 Linked post: How to use MouseListener to find a specific cell in a grid I am trying to create a Battleships game, with a 10x10 grid made up of 100 cells. The Grid extends JPanel and the Cell also extends JPanel. Earlier on I made the link above to ask how to implement a MouseListener to do this. As the code is all on that page, I am just going to refer to it. Someone posted an excellent answer on that link which I accepted. I can now use MouseListener to detect movement, clicks etc in any

Auto loop-scrolling active contents in JPanel - marquee text

蹲街弑〆低调 提交于 2019-12-24 03:26:32
问题 I need some auto loop-scrolling (marquee text) it's contents JPanel . It contents must react on mouse clicking on different elements. So just drawing contents with moved coordinates not working here, because real position of elements not changing. Also it must be update able. Most likely that it will be smooth update - without any bouncing. Tried to use JScrollPane with no visible scrollers and auto-scrolling, it can hold action listeners, but I can't make it smooth looping and smooth

Java gridbaglayout problems

别说谁变了你拦得住时间么 提交于 2019-12-24 03:07:51
问题 I'm having problems adjusting my combobox so it is closer to the 'band directory' label. How do i move the combobox to the left, just 5px besides the label. I have tried setting horizontal insets for my label and negative insets for my combobox but that still did not work. Here is my code: public void createGUI() { main_panel = new JPanel(); main_panel.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); label = new JLabel("Band Directory:"); band_combobox = new

Java Swing. Opening a new JPanel from a JButton and making the buttons pretty

岁酱吖の 提交于 2019-12-24 02:09:29
问题 I am trying to build a little program that has a main GUI with 2 buttons. One button closes the program, the other I want to open a new JPanel that will have text fields etc. I would like to be able to make the buttons so they look like normal application buttons I guess, nice and square, equal size etc. etc., I am not sure how to do this though. Also, I am unsure how to open a new JFrame from a button click. GUI Code: package practice; public class UserInterface extends JFrame { private

Drawing partially transparent PNG onto JPanel

跟風遠走 提交于 2019-12-24 01:05:06
问题 How would i go about drawing a partially transparent image onto a JPanel by overriding its void paint (Graphics g) method? I've tried the obvious way, which is to load the image and then use ((Graphics2D)g).drawImage(...) but that didn't work, and the internet isn't telling me much. 回答1: JLabel is capable of doing this, but if you want to do something else with the panel/image, the using paintComponent and Graphics#drawImage is also an option. Using this as a base... I was able to render this

JPanel size is not known on start

▼魔方 西西 提交于 2019-12-24 00:20:06
问题 When I create a Board instance from my Square instance, I try to assign the size of the window to the integers x and y. I fail to do this because it seems like on start the size is 0. In the constructor in Board.java, x and y shouldn't be -50 like they end up now. Square.java: package Square; import javax.swing.*; public class Square extends JFrame { public Square(){ add(new Board()); setSize(800, 800); setVisible(true); } public static void main(String[] args){ new Square(); } } Board.java

Image not repainting, just multiplying

谁说胖子不能爱 提交于 2019-12-24 00:05:15
问题 I have a JPanel implements a key listener. It pulls and displays an Image pulled from another class. NA the Key listener is passed to that class to get one of many images and move it 2px in a direction. My problem is that the old image does not disappear when I call repaint(), so i get a line of images. The thing is that when i combined the class with the image and the JPanel class in to one bi final it worked perfectly. I have done some research on this and i found double buffering. If i

Border Layout not working

旧时模样 提交于 2019-12-23 23:36:29
问题 I've been trying to setup this border layout for hours. I've looked up How to Use BorderLayout on the Java website but I still haven't gotten it. I've included my code below for review and to make it easier to see how I am trying to use the BorderLayout function. How do I setup a border layout on JL3? class GameStructure { private String []wordList = {"computer","java","activity","alaska","appearance","article", "automobile","basket","birthday","canada","central","character","chicken","chosen