jpanel

Using JPanel to draw straight lines and get point coordinates

久未见 提交于 2019-12-06 11:23:50
I am at a total loss right now. I haven't worked much with building GUIs in Java, I've been reading all about swing and JPanel, and I think what I am trying to do is possible, I just haven't figured out how . I'm trying to build a GUI in which you can draw straight lines within a certain drawing area, I would like to be able to get the start/endpoint coordinates in order to perform some math with those points. Any help would be greatly appreciated! I will leave the code to you so here is the algorithm: 1. Create a JFrame and add a JPanel to it. 2. Add a mouse listener for the JPanel 3. Every

Update LookAndFeel Values On The Fly

吃可爱长大的小学妹 提交于 2019-12-06 10:12:33
I want to be able to update the LookAndFeel attributes of my Swing GUI on the fly. In this case, I have a simple Swing/Awt game running what starts out as the Nimbus LookAndFeel . At various points after start up I want to change (let us say) just one detail: the background color of my application. I can change the background color by doing this: for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); UIManager.getLookAndFeelDefaults().put("Panel.background", Color.RED); SwingUtilities

Two Different Panels in One Frame - Java

拜拜、爱过 提交于 2019-12-06 09:43:20
问题 I have a question. I have one main frame, and to the left i have a sidebar with menus. My question is, is it possible to make another panel within the main frame, so that if menu1 is clicked, the related contents should be displayed to the second half of the main frame, and when other menus are pressed then obviously the relevant stuff according to what is selected. its a bit hard to explain, sorry. Has anyone got an idea, whether that is possible in Java with Eclipse? 回答1: yes this's pretty

How to put an image in a specific JPanel?

安稳与你 提交于 2019-12-06 09:23:44
I am experimenting with board games lately and now I am making a Checkers board game. However I cannon figure out how to display a chip in a cell of the GridLayout . Each cell has it's own JPanel that I assigned in a 2D Array by a FOR Loop . I need to display the image p1Chip which is just a .png in a specific JPanel , lets say it's variable name name is board[2][3] , without messing up the GridLayout . A sample code on how I can do this would be great as it will help me out understand better. I have searched the internet but I can't find what I need, or at least something that explains how to

Parent JPanel - How to listen to the events generated by components of a Child JPanel? [duplicate]

眉间皱痕 提交于 2019-12-06 09:12:29
This question already has answers here : Adding ActionListener to a Panel - Panel implements ActionListener vs Panel HAS A ActionListener (2 answers) Closed 6 years ago . I made a JPanel Child which contains a couple of radio buttons in it. Whenever a radio button is clicked i want an ActionEvent to be generated from the Child also. This action event should "contain" a reference to the button which actually generated an event. This Child will be used as a component inside another JPanel Parent which will listen to the events from the Child, instead of listening to the individual radio buttons.

Java Swing: Clearing custom painting from a JPanel overlayed with other JPanels in a JLayeredPane

谁说胖子不能爱 提交于 2019-12-06 08:54:10
I've got a JLayeredPane containing three JPanels, two of which overlap, that I'm painting shapes to. One of the two JPanels that overlap needs to have every shape drawn to it cleared without affecting the shapes drawn to the JPanel under it disappear from the screen. Currently I'm using something like this: Graphics g = pane2.getGraphics(); g.clearRect (0, 0, 1000, 1000); But this not only clears everything painted to pane2 but also pane1, which is under it. So my question is: Is there any way to clear everything painted to one JPanel without affecting anything painted to a JPanel under it? I

How can I replace one JPanel with another JPanel in the same position?

匆匆过客 提交于 2019-12-06 08:12:34
问题 I have a JFrame with about four frames. After a given action I want to replace one panel with another in the same position. My method for switching them looks like this (the this object is a class which extends JFrame ): public void switchPanel(){ mainPanel.remove(introPanel); mainPanel.add(questionPanel); this.repaint(); } The original creation of the window looks like this: mainPanel.add(titlePanel); mainPanel.add(sidePanel); mainPanel.add(introPanel); 回答1: You ask: How can I replace one

How do I remove an old JPanel and add a new one?

假装没事ソ 提交于 2019-12-06 06:52:30
I would like to remove an old JPanel from the Window (JFrame) and add a new one. How should I do it? I tried the following: public static void showGUI() { JFrame frame = new JFrame("Colored Trails"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(partnerSelectionPanel); frame.setSize(600,400); frame.setVisible(true); } private static void updateGUI(final int i, final JLabel label, final JPanel partnerSelectionPanel) { SwingUtilities.invokeLater( new Runnable() { public void run() { label.setText(i + " seconds left."); } partnerSelectionPanel.setVisible(false); \\ <------------

Java trouble with ArrayLists when there are multiple classes and help fixing up the code [closed]

岁酱吖の 提交于 2019-12-06 06:37:40
Closed . This question needs details or clarity . It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post . Closed 5 years ago . I've come to the conclusion that I have 3 questions. How do I use the variables and arrayList of the company class in the Employee class. How should I make the actionListeners so the operate correctly. Would the methods in the Company class work correctly? If not, how should I make them? Check the link given in the paragraph above for the prompt to my question. Here is a link to the prompt my

Making Table With List Of JPanels ( With Applying Percentage Size Columns )

旧时模样 提交于 2019-12-06 04:41:00
In this post Making Table With List Of JPanels I can make a Table with lists of panel. And this table has many features but I need to a new feature and it is applying percentage columns.It means I like to width of all columns not equals and with a array of floats determines. This is my class table : import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Vector; public class PanelTable extends JPanel { private String data[][]; private String columns[]; private int numberOfRows; private int numberOfColumns; private